I'm new to laravel notification I want when to click on the notification the link takes me to the invoice and the notification should be marked as read I don't know how to mark one notification as read. I know that I should take the notification id to mark the specific notification as read but I don't know how to is it in a function.
blade :
<div id="unreadNotifications">
@foreach (auth()->user()->unreadNotifications as $notification)
<div class="main-notification-list Notification-scroll mark-as-read" >
<a class="d-flex p-3 border-bottom"
href="{{ url('InvoicesDetails') }}/{{ $notification->data['id'] }}" data-id="{{$notification->id}}" >
<div class="notifyimg ">
<i class="la la-file-alt text-pink text-center"></i>
</div>
<div class="ml-3">
<h5 class="notification-label mb-1">
{{ $notification->data['title'] }}
{{ $notification->data['user'] }}
</h5>
<div class="notification-subtext">{{ $notification->created_at }}
</div>
</div>
</a>
</div>
@endforeach
</div>
Controller:
public function MarkAsRead_all (Request $request)
{
$userUnreadNotification= auth()->user()->unreadNotifications;
if($userUnreadNotification) {
$userUnreadNotification->markAsRead();
return back();
}
}
public function unreadNotifications_count()
{
return auth()->user()->unreadNotifications->count();
}
public function unreadNotifications()
{
foreach (auth()->user()->unreadNotifications as $notification){
return $notification->data['title'];
}
Create a link in the blade
Define a route for it
In Controller