Laravel通知发生广播500内部服务器错误

时间:2017-07-03 12:31:42

标签: php laravel push-notification broadcast

当我写

时,我正试图在laravel 5.3中播放通知
  public function via($notifiable)
{
    return ['broadcast','database'];
}
控制台 500内部服务器错误出现

错误,当我删除广播错误删除时,请帮助这里是我的通知代码

<?php
 namespace App\Notifications;

use Illuminate\Bus\Queueable;    
use Illuminate\Notifications\Notification;    
use Illuminate\Contracts\Queue\ShouldQueue;    
use Illuminate\Notifications\Messages\MailMessage;    
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Notifications\Messages\BroadcastMessage;


class userLiked extends Notification implements ShouldBroadcast, ShouldQueue
{

use Queueable;

/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct()
{
    //
}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['broadcast','database'];
}

    /**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toDatabase($notifiable)
{
    return [
        'status'=>'liked',
        'user'=>auth()->user(),
    ];
}

    /**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array|BroadcastMessage
     */
public function toBroadcast($notifiable)
{
    return new BroadcastMessage(array(
        'status'=>'liked',
        'user'=>auth()->user(),
    ));
}
/**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toArray($notifiable)
{
    return [
        //
    ];
}
}

这是我的cotroller代码,我在呼叫通知

        $like = new like();
        $like->userId = $request['userId'];
        $like->crushId = $request['crushId'];
        $like->liked = true;
        $like->save();
       User::find($like->crushId)->notify(new userLiked());

这是我的用户模型

<?php

namespace App;

use Illuminate\Support\Facades\Auth;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use Notifiable;

public function likes(){
    $this->hasMany('App\like');
}

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'username', 'email', 'password',
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];





/**
 * @return string
 */
public function receivesBroadcastNotificationsOn()
{
    return 'user.'.$this->id;
}

}

请帮助我生病了

0 个答案:

没有答案