恕我直言,当前用于在Laravel中保存通知的数据库通道是非常糟糕的设计:
data列中搜索自定义属性(转换为Array)不是最佳选择您将如何DatabaseNotification在供应商包中扩展模型?
我想添加列event_id,question_id,user_id(在创建该通知用户)等等为默认laravel notifications表
如何覆盖send函数以包含更多列?
在:
vendor/laravel/framework/src/Illuminate/Notifications/Channels/DatabaseChannel.php
Run Code Online (Sandbox Code Playgroud)
代码:
class DatabaseChannel
{
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return \Illuminate\Database\Eloquent\Model
*/
public function send($notifiable, Notification $notification)
{
return $notifiable->routeNotificationFor('database')->create([
'id' => $notification->id,
'type' => get_class($notification),
\\I want to add these
'user_id' => \Auth::user()->id,
'event_id' => $notification->type =='event' ? $notification->id : null,
'question_id' => $notification->type =='question' ? …Run Code Online (Sandbox Code Playgroud)