How to Display Laravel notification
The notification system in Laravel allows you to send notifications to users over different mail, database, broadcast, and slack channels. Today, we’ll discuss how you display Laravel notification.
#resources/views/home.blade.php
@if(auth()->user()->notifications->count())
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Notication <sup class="btn btn-danger btn-sm rounded">{{ auth()->user()->readnotifications->count() }}</sup> <sup class="btn btn-success btn-sm rounded"> {{ auth()->user()->unreadnotifications->count() }}</sup> </div>
<div class="card-body">
@foreach(auth()->user()->notifications as $notification)
@if($notification->read_at)
<p class="text-danger">{{ $notification->data['data'] }}</p>
@else
<p class="text-success">{{ $notification->data['data'] }}</p>
@endif
@endforeach
@if(auth()->user()->unreadnotifications->count())
<a href="{{ route('markAsRead') }}" class="btn btn-default border border-success text-success">Mark as read.</a>
@endif
</div>
</div>
</div>
</div>
@endif
#route/web.php
Route::get('markAsRead', 'HomeController@markasread')->name('markAsRead');
#app/Http/Controllers/HomeController.php
public function markasread(Request $request) {
$success = auth()->user()->unreadNotifications->markAsRead();
return redirect()->back();
}