我无法将通知存储到数据库内的通知表中, 我试图在每次有新帖子时发出通知,我该如何进行这项工作。
错误:
通知:
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');
}
答案 0 :(得分:1)
您需要将帖子注入结构中,否则它永远都不会解决。
protected $post;
public function __construct(Post $post)
{
$this->post = $post;
}