【发布时间】:2017-01-16 08:30:22
【问题描述】:
我正在使用 Laravel 5.3 通知。
我成功创建了数据库通知以及如何向目标用户显示所有或未读的通知。
例如,这是我的通知类,通知用户她在课程中的注册状态:
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' => '#'
];
}
}
并显示我在刀片模板中编写的所有通知:
<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>
一切正常,但现在我想实现它的实时性。
我知道我可以使用Pusher 和Pusher bridge。我安装 Pusher 桥接器并遵循Building Real-Time Laravel Apps with Pusher 指导。
但我不知道如何在我的通知中使用它?如何在via() 方法中定义它?我该怎么做?
【问题讨论】:
标签: php laravel laravel-5.3