【问题标题】:laravel notifications not storing into my database plus errorlaravel 通知未存储到我的数据库中加上错误
【发布时间】:2019-01-11 05:06:23
【问题描述】:

我无法将通知存储到数据库内的通知表中, 每次有新帖子时我都试图发出通知,我该如何进行这项工作。

错误:

通知:

use Queueable;
public $post;


public function __construct()
{

}


public function via($notifiable)
{
    return ['database'];
}


public function toDatabase($notifiable)
{
    return [
        'title' => $this->post->title,
    ];
}


public function toArray($notifiable)
{
    return [

    ];
}

}

后控制器:

public function store(Request $request)
{

    $this->validate($request, [
        'title'=>'required|max:100',
        'body' =>'required',
        ]);

    $title = $request['title'];
    $body = $request['body'];

    $post = Post::create($request->only('title', 'body'));


   Auth::user()->notify(new NotifyPost($post));


    return redirect()->route('posts.index')
        ->with('flash_message', 'Article,
         '. $post->title.' created');
}

【问题讨论】:

    标签: laravel notifications pusher


    【解决方案1】:

    您需要在构造中注入帖子,否则它永远不会得到解决。

    protected $post;
    
    public function __construct(Post $post)
    {
        $this->post = $post;
    }
    

    【讨论】:

    • 请试试我的建议。如果它仍然不起作用,请告诉我错误。
    猜你喜欢
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 2021-02-08
    • 2023-01-15
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    相关资源
    最近更新 更多