I am working with Laravel 5.3 Notifications.
I succeed to create database notifications and how to show all or unread those to target user.
For example this is my notification Class that notif to user her register Status in a Course :
class NewChangeRegisterStatusNotif extends Notification
{
use Queueable;
public function __construct ($status_id, $course_id)
{
$this->status = CourseUserStatus::findOrFail($status_id);
$this->course = Course::findOrFail($course_id)->first(['title']);
}
public function via ($notifiable)
{
return ['database'];
}
public function toMail ($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', 'https://laravel.com')
->line('Thank you for using our application!');
}
public function toArray ($notifiable)
{
return [
'message' =>
' Your Status in ' .
'<strong class="text-default">' . $this->course->title . '</strong>'
. ' Course has changed to ' .
'<strong class="text-' . $this->status->label . '">' . $this->status->title . '</strong>';
,
'action' => '#'
];
}
}
And to show all Notification I wrote in a blade template this :
<ul class="menu">
@foreach($AuthUser->unreadNotifications as $notif)
<li>
<a href="{{$notif->data['action']}}" data-notif-id="{{$notif->id}}">
{!! $notif->data['message'] !!}
</a>
</li>
@endforeach
</ul>
All things work fine But Now I want to make that real-time.
I know that I can use Pusher and Pusher bridge. I install Pusher bridge and follow Building Real-Time Laravel Apps with Pusher guidance.
But I do not know how to use it in My notification? how can I define it in via()
method?and what I do?