laravel - 默认 laravel 通知 --> 数据不工作
问题描述
我正在尝试使用默认的 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
但我什么也没得到......有人有想法吗?
解决方案
推荐阅读
- xpath - 如果孩子没有特定的属性值,则获取父母的属性值
- sql-server - 如何配置 SSMA 以生成忽略 NULL 的过滤唯一索引?
- jsf - 在 p:textEditor 中添加或附加文本
- mongodb - MongoDb 聚合将输出合并到一个数组中,而我需要作为单独的记录
- java - Spigot 1.16.1 中不推荐使用 PlayerChatTabCompleteEvent
- python - 在 post 请求中提取 json 数据
- javascript - ReferenceError:哈希未在 node.js 中定义
- java - 检查是否启用默认值的 javaUnit
- git - 如何通过 Internet 为私有存储库配置 Bonobo git
- mysql - 从表中获取所有字段并在特定条件下标记一些