0

当有人喜欢并评论他的帖子时,我正在尝试向帖子的所有者发送通知,评论通知正在工作,但是当我为喜欢做同样的工作时它不起作用。

这是我的通知类

<?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));
 }
4

0 回答 0