简体   繁体   English

laravel 5.3数据库通知定制

[英]laravel 5.3 database notification customization

I am creating laravel 5.3 database notifications.I have created notifications as per video published on https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/10 , Now i want to add custom fields to the notification table as per my requirements. 我正在创建laravel 5.3数据库通知。我已根据https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/10上发布的视频创建了通知,现在我要添加自定义字段根据我的要求到通知表。 Please help me how to pass custom data to notification and access it. 请帮助我如何将自定义数据传递给通知并访问它。

When I needed to put custom fields to Notification, I'd just put on data field, as it is a Json field, works perfectly. 当我需要将自定义字段放入Notification时,我只是放置数据字段,因为它是一个Json字段,完美地工作。 Like this: 像这样:

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
        ];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM