public function handle()
{
//通知每个用户系统消息
$users = \App\User::all();
foreach($users as $user){
$user->addNotice($this->notice);
}
}
}
public function store(){
$this->validate(request(),[
'title' => 'required|string',
'content' => 'required|string',
]);
$notice = \App\Notice::create(request(['title','content']));
dispatch(new \App\Jobs\SendMessage($notice));
return redirect('/admin/notices');
}
//用户收到的通知
public function notices(){
return $this->belongsToMany(\App\Notice::class,'user_notice','user_id','notice_id')->withPivot(['user_id','notice_id']);
}
//给用户增加通知
public function addNotice($notice){
return $this->notices()->save($notice);
}
添加一条通知后,没报错,user_notice表中没有数据,老师这是为什么
Laravel最新特性结合Mysql异步消息队列、ElasticSearch搜索引擎、Debugbar调试利器开发简书
了解课程