【问题标题】:Laravel Private Channel Not Authorizing : Error 404Laravel 私人频道未授权:错误 404
【发布时间】:2019-07-03 15:30:55
【问题描述】:

我正在尝试构建一个实时通知系统。我使用了 Laravel-Notifications 和 laravel-echo-server。当我在终端 laravel-echo-server start 中使用 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);
});

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    我已经解决了这个问题,错误在 larvel echo 的路径中。

    原来是

    http://localhost

    应该是

    http://localhost:8000

    【讨论】:

    • 路径是什么意思?
    猜你喜欢
    • 2020-07-23
    • 2020-01-06
    • 2021-10-17
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 2012-12-04
    相关资源
    最近更新 更多