laravel 5.3数据库通知自定义

Dax*_*Dax 6 php laravel-5

我正在创建laravel 5.3数据库通知.我已根据https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/10上发布的视频创建了通知,现在我要添加自定义字段根据我的要求到通知表.请帮助我如何将自定义数据传递给通知并访问它.

Raf*_*lQm -1

当我需要将自定义字段放入通知时,我只需放入数据字段,因为它是 Json 字段,效果非常好。像这样:

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

class TaskNotification extends Notification
{
    use Queueable;

    private $message;

    /**
     * @param String $message
     */
    public function __construct($message=false)
    {
        if ($message)
            $this->message = $message;
    }

    /**
     * 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 [
            'message' => $this->message,
            'link' => route('mymodel.show'),
            'task'=> 1, // This is one variable which I've created
            'done'=> 0 // This is one variable which I've created
        ];
    }
}
Run Code Online (Sandbox Code Playgroud)