Laravel - Notifications - Marking Notifications As Read

Typically, you will want to mark a notification as "read" when a user views it. The Illuminate\Notifications\Notifiable trait provides a markAsRead method, which updates the read_at column on the notification's database record:

    
    $user = App\Models\User::find(1);
    
    foreach ($user->unreadNotifications as $notification) {
        $notification->markAsRead();
    }
	

However, instead of looping through each notification, you may use the markAsRead method directly on a collection of notifications:

    
    $user->unreadNotifications->markAsRead();
	

You may also use a mass-update query to mark all of the notifications as read without retrieving them from the database:

    
    $user = App\Models\User::find(1);
    
    $user->unreadNotifications()->update(['read_at' => now()]);
	

You may delete the notifications to remove them from the table entirely:

    
    $user->notifications()->delete();