我正在尝试向帖子的所有者发送通知,当有人喜欢并评论他的帖子时,评论通知正在发挥作用但是当我为喜欢做同样的工作时它无法正常工作。
这是我的通知类
<?php
namespace App\Notifications;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class show_notification extends Notification
{
use Queueable;
protected $comment;
protected $likes;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($comment,$likes)
{
$this->comment = $comment;
$this->likes = $likes;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
'comment' => $this->comment,
'likes' => $this->likes,
'user' => auth()->user()
//'repliedTime' => Carbon::now()
];
}
public function toArray($notifiable)
{
return [
//
];
}
}
我的控制器功能代码,用于评论通知
$id = $comment->post_id;
$getuser = Post::where('id', $id)->first();
$userid = $getuser->user_id;
if ($userid != $user_id ){
$user = User::where('id', $userid)->first();
$user->notify(new show_notification($comment));
}
我喜欢的通知的控制器功能代码
$id = $likes->post_id;
$getuser = Post::where('id', $id)->first();
$userid = $getuser->user_id;
if ($userid != $user_id ){
$user = User::where('id', $userid)->first();
$user->notify(new show_notification($likes));
}