Laravel雄辩的通知值不正确
当用户的一篇文章被“喜欢”时,我会用拉威尔的通知给他们发电子邮件 我遇到的问题是,当用户收到电子邮件时,计数的likes值是错误的(该值太低) 例如,一个帖子有2个喜欢,一个用户喜欢它,这个帖子现在有3个喜欢,但是收到的邮件表明这个帖子有2个喜欢 这是因为通知是在数据有机会保存到数据库之前触发的吗 文章->喜欢(): 当一篇文章被喜欢时。。。。 (如电子控制器) 通知类(大部分)Laravel雄辩的通知值不正确,laravel,email,notifications,eloquent,Laravel,Email,Notifications,Eloquent,当用户的一篇文章被“喜欢”时,我会用拉威尔的通知给他们发电子邮件 我遇到的问题是,当用户收到电子邮件时,计数的likes值是错误的(该值太低) 例如,一个帖子有2个喜欢,一个用户喜欢它,这个帖子现在有3个喜欢,但是收到的邮件表明这个帖子有2个喜欢 这是因为通知是在数据有机会保存到数据库之前触发的吗 文章->喜欢(): 当一篇文章被喜欢时。。。。 (如电子控制器) 通知类(大部分) 我们能在LikeControl中看到整个方法吗?当然,我已经更新了原始帖子,显示了涉及的完整函数Hanks bro:
我们能在LikeControl中看到整个方法吗?当然,我已经更新了原始帖子,显示了涉及的完整函数Hanks bro:)。运行return()->markdown()。。return()->view()没有运行我。我们可以在LikeControl中看到整个方法吗?当然,我已经更新了原始帖子,以显示涉及的完整函数Hanks bro:)。运行return()->markdown()。。return()->view()不运行我。
/**
* Article morphs many Like.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function likes( )
{
// morphMany(MorphedModel, morphableName, type = able_type, relatedKeyName = able_id, localKey = id)
return $this->morphMany(Like::class, 'likeable');
}
public function getLikeArticle($id)
{
$blog = Article::findOrFail($id);
if(Auth::user()->hasLikedArticle($blog))
{
return redirect()
->back()
->with('info-error', 'You have already liked that Post.');
}
$like = $blog->likes()->create([
'user_id' => Auth::user()->id
]);
Auth::user()->likes()->save($like);
$user = $blog->user;
if(Auth::user()->id !== $user->id)
{
$user->notify(new UserLikedArticle($blog, Auth::user()));
}
return redirect()
->back()
->with('info-success', 'Success, you like this');
}
use App\Models\Article\Article;
use App\Models\User\User;
class UserLikedArticle extends Notification
{
use Queueable;
protected $article;
protected $author;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Article $article, User $author)
{
$this->article = $article;
$this->author = $author;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail', 'broadcast', 'database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)->markdown('email.notification.like.article', ['author' => $this->author, 'article' => $this->article]);
}