laravel通知未存储到我的数据库中,并显示错误

时间:2018-08-03 10:10:54

标签: laravel notifications pusher

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

错误:

enter image description here

通知:

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');
}

1 个答案:

答案 0 :(得分:1)

您需要将帖子注入结构中,否则它永远都不会解决。

protected $post;

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