Laravel专用频道未授权:错误404

时间:2019-02-09 17:05:47

标签: php laravel

我正在尝试构建一个实时通知系统。我使用了Laravel-Notifications和laravel-echo-server。当我在终端laravel-echo-server start中使用启动命令监听通知时,在私有通道中发生了错误:

  

客户端无法通过身份验证,HTTP状态为404⚠[6:57:15 PM]-   无法将qXY1YTBcnGUzqJvfAAAB认证为private-App.User.2

客户端无法通过身份验证,HTTP状态为404

代码

channels.php

Broadcast::channel('App.User.{id}', function ($user, $id) {
 return (int) $user->user_id === (int) $id;
});

通知

class StickBoardLiked extends Notification
{
use Queueable;

protected $boardid;


/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct($boardid)
{
    $this->boardid = $boardid;
}

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

/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    return (new MailMessage)
                ->line('The introduction to the notification.')
                ->action('Notification Action', url('/'))
                ->line('Thank you for using our application!');
}

/**
 * Get the array representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function toArray($notifiable)
{
    return [
        //
        'liked_by' => Auth::user()->user_id,
        'username' => Auth::user()->user_name,
        'board_id' => $this->boardid,
        'content_type' => 'like',

    ];
}
}

用于监听通知的前端脚本

Echo.private("App.User." + this.user.user_id).notification(notification 
=> {
  this.unreadNotifications.push(notification);
});

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,错误发生在幼虫回声的路径上。

  

http://localhost

过去是

  

http://localhost:8000