【问题标题】:laravel 5.3 database notification customizationlaravel 5.3 数据库通知自定义
【发布时间】:2017-09-01 16:09:11
【问题描述】:

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

【问题讨论】:

  • 遇到类似问题,请大家帮忙
  • 找到解决办法了吗?
  • 我也是,似乎通知太年轻了,或者没有足够的文档来有效地使用它

标签: php laravel-5


【解决方案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
        ];
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-23
    • 2017-09-24
    • 1970-01-01
    • 2017-03-31
    • 2017-02-28
    • 1970-01-01
    • 2021-07-23
    • 2017-04-27
    相关资源
    最近更新 更多