首页 > 解决方案 > 如何获取文章所有者 user_id 并保存到 notifiable_id 字段

问题描述

如何获取文章所有者 user_id 并保存到 notifiable_id 字段假设 $articlecomment = $article_owner_id

我的代码:

$articlecomment = new Article_comment();
$articlecomment->user_id  = Auth::user()->id;//Comment by user id
$articlecomment->article_id = $request->articleid;
$articlecomment->comment    = $request->comment;
$articlecomment->save();   
auth()->user()->notify(new ArticleNotification($articlecomment));
//$articlecomment->user()->notify(new ArticleNotification($articlecomment));

数据库屏幕截图我想要 notifible_id 字段上的 article_owner_user_id 在此处 输入图像描述

标签: laravelnotify

解决方案


Solved 
 $articlecomment->save();
 $article = Article::where('id','=',$request->articleid)->first();
 if($article->user_id != Auth::User()->id){
 $article->user->notify(new ArticleNotification($article));
 }

推荐阅读