php - Laravel 广播通知错误:客户端无法通过身份验证,获得 HTTP 状态 404
问题描述
我正在尝试构建一个实时通知系统。我使用了 Laravel-Notifications 和 laravel-echo-server。当我在终端 laravel-echo-server start 中使用 start 命令收听通知时,私人频道发生错误:
⚠ [下午 4:36:43] - H12aWYBsF5UdR5NYAAAH 无法通过 private-App.Domain.User.User.1 的身份验证
客户端无法通过身份验证,获得 HTTP 状态 404
代码
// 频道.php
Broadcast::channel('App.Domain.User.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;});
// 通知文件代码 (ListingApproved.php)
class ListingApproved extends Notification implements ShouldQueue {
use Queueable;
private $listing;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Listing $listing)
{
$this->listing = $listing;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database', 'broadcast'];
}
public function toArray($notifiable)
{
return $this->listing->id;
}
public function toBroadcast($notifiable)
{
return new BroadcastMessage([
'invoice_id' => $this->listing->id
]);
}}
//监听通知的前端脚本
Echo.private('App.Domain.User.User.' + '{{ auth()->user()->id }}')
.listen(".Illuminate\\Notifications\\Events\\BroadcastNotificationCreated", (notification) => {
console.log('yes');
console.log(notification.type);
});
解决方案
它可能与您的回声服务器auth host
配置有关,
您可以使用 laravel echo server 和 redis 检查例如 laravel 实时应用程序,
Laravel / Redis / Socket.IO / Laravel-Echo 的实时应用示例
我希望这个能帮上忙
推荐阅读
- c++ - OpenGL:使用鼠标移动 2D 正交相机
- r - 无法过滤带有串扰的传单多边形
- flutter - 我对我不太理解的位置参数有错误。请帮忙
- xamarin - Telerik RadChart 有 2 个图表时不显示
- javascript - 在 sessionStorage 中保存 userId 给出错误?
- javascript - 如何使用 Ant Design Vue 禁用 Select 中的特定元素?
- sql - 如何将时间戳从sas转换为普通时间戳
- pandas - 将多种类型的值转换为整数值
- r - 如何获取包含多个不同 URL 的字符串列表并将它们转换为 R 上的可点击链接?
- python - 当熊猫系列中的元素是列表时如何运行数组操作