【发布时间】:2021-07-17 15:20:45
【问题描述】:
我使用的是 Laravel 默认的 notifications 系统。但是,我需要在notifications 表中添加一个额外的列来检查用户是否已经拥有相同的未读通知。
例如:如果用户的个人资料不完整,则每次登录时都会提醒他/她,直到个人资料完成。但是如果之前生成的通知仍然是unread,则不会生成新的notification。
表格:通知
| default_fields | notify | ... |
|---|---|---|
| ... | profile_incomplete | ... |
| ... | password_change_overdue | ... |
通知类
class NotifyToCompleteProfileNotification extends Notification
{
public function __construct()
{
$this->notify = 'profile_incomplete';
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'data' => '...',
];
}
}
【问题讨论】:
-
默认的 Laravel 通知系统已经有
type列携带使用的通知类名。 -
是的,我知道。这只是一个例子。
-
知道了,看看我的答案。
标签: php laravel notifications customization