Mark as read a specific notification in Laravel 5.3 Notifications
You must first make sure that the notification exists first so that you can make adjustments to it and I do not recommend using the unreadNotifications object because in the event that there are no unread notifications an error will occur because of that
$notification_id = "03fac369-2f41-43d0-bccb-e364aa645f8a";
$Notification = Auth::user()->Notifications->find($notification_id);
if($Notification){
$Notification->markAsRead();
}
or you can directly edit without any check
DB::table('notifications')->where('id',$notification_id)->update(['read_at'=>Carbon::now()])
This works without fail:
$id = auth()->user()->unreadNotifications[0]->id;
auth()->user()->unreadNotifications->where('id', $id)->markAsRead();
$notification = auth()->user()->notifications()->find($notificationid);
if($notification) {
$notification->markAsRead();
}
According to this Answer on Github, solution is :
Illuminate\Notifications\DatabaseNotification
is where the Model for the notifications exists, you can use it to grab a notification by ID and delete it. Also if you don't want to use the model you can use a normal DB query.