我正在尝试构建一个实时通知系统。 我使用了Laravel-Notifications和laravel-echo-server。 当我在终端laravel-echo-server start中使用start命令监听通知时,私有频道出现错误:
⚠[4:36:43 PM] - H12aWYBsF5UdR5NYAAAH无法通过private-App.Domain.User.User.1进行身份验证。
客户端无法通过身份验证,获得HTTP状态404
CODE
// channels.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);
});
答案 0 :(得分:0)
它可能与您的echo服务器auth host
配置相关,
您可以使用laravel echo server和redis来检查laravel实时应用程序,
Real time application example with Laravel / Redis / Socket.IO / Laravel-Echo
我希望这会有所帮助