gpt4 book ai didi

php - Laravel 私有(private) channel 未授权 : Error 404

转载 作者:搜寻专家 更新时间:2023-10-31 21:20:02 27 4
gpt4 key购买 nike

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

Client can not be authenticated, got HTTP status 404 ⚠ [6:57:15 PM] - qXY1YTBcnGUzqJvfAAAB could not be authenticated to 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);
});

最佳答案

我已经解决了这个问题,错误出现在幼虫 echo 的路径上。

原来是

http://localhost

应该是

http://localhost:8000

关于php - Laravel 私有(private) channel 未授权 : Error 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54608519/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com