首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >laravel 5.3数据库通知自定义

laravel 5.3数据库通知自定义
EN

Stack Overflow用户
提问于 2017-04-06 22:40:20
回答 1查看 550关注 0票数 6

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

EN

回答 1

Stack Overflow用户

发布于 2018-08-22 04:00:27

当我需要将自定义字段放到Notification中时,我只需放入数据字段,因为它是一个Json字段,可以完美地工作。如下所示:

代码语言:javascript
复制
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
        ];
    }
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43258381

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档