我有数据库通知,每当他们单击通知链接之一时,我都试图重定向用户,它将转到确切的POST ID,然后将其标记为已读,即选中了该特定通知。但我无法使其工作
这是我的控制人
public function readbyid($id){
if(isset($notification->data['id'])){
return redirect()->action(
'PostController@show', ['id' => $notification->data['id']]
);
}else{
return redirect()->back();
}
}
通知模型
public function toArray($notifiable)
{
return [
'id' => $this->post->id,
];
}
刀片视图:
<li class="nav-item dropdown"> <a id="messages" rel="nofollow" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link"><i class="fa fa-bell"></i>@if (auth()->user()->unreadnotifications->count())<span class="badge badge-warning">{{auth()->user()->unreadnotifications->count()}}</span>@endif</a>
<ul aria-labelledby="notifications" class="dropdown-menu">
<li><a rel="nofollow" href="{{Url('markread')}}" class="dropdown-item all-notifications text-center"> <strong> <i class="fa fa-bell"></i>Mark all as Read</strong></a></li>
@foreach(auth()->user()->unreadnotifications as $notify)
<li><a rel="nofollow" href="{{Url('markread/{id}')}}" class="dropdown-item d-flex">
<div class="msg-body">
<h3 class="h5">{{$notify->data['title']}}</h3>
</div> </a></li>@endforeach
</ul>
</li>
路线:
Route::get('markread/{id}', 'NotifyController@readbyid' );