我正在尝试使用默认的Laravel通知,但我不明白为什么它不显示数据。
这是我的代码
/notification/NewReply.php
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class NewReply extends Notification
{
use Queueable;
public $user;
public $association;
public $opportunity;
public function __construct($user, $association, $opportunity)
{
$this->user = $user;
$this->opportunity = $opportunity;
$this->association = $association;
}
public function via($notifiable)
{
return ['database'];
}
public function toDatabase($notifiable)
{
return [
'user_id' => $this->user->id,
'association_name' => $this->association->association_name,
'opportunity_id' => $this->opportunity->id,
'opportunity_name' => $this->opportunity->title,
];
}
}
这是我触发通知的方式
$company->notify(new NewReply(Auth::user(),$association,$opportunity));
这是触发后保存的数据字段,是正确的
{"user_id":2,"association_name":"Super delter","opportunity_id":1,"opportunity_name":"Afro tenders"}
我会像文档
这样回显@foreach(Auth::user()->notifications as $notification)
<p>{{$notification->data['association_name']}}</p>
@endforeach
但是我什么也没得到...有人有主意吗?