在我的 Laravel Framework 5.7/Vuejs 2.6 中,我使用 jwt.auth 并安装 pusher
我检查我的页面的 xsfr token https://imgur.com/a/CveJ6jh但我在 http://local/broadcasting/auth 中收到 419 错误请求并打开此 URL 的响应我看到页面过期消息。
在 app/Events/NewMessage.php 中:
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\Message;
class NewMessage
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Message $message)
{
$this->message= $message;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('messages.'.$this->message->to);
}
public function broadcastWith()
{
return ['messages' => $this->message];
}
}
在 routes/channels.php 中:
Broadcast::channel('messages.{id}', function ($user, $id) {
dd($user->id, $id);
return (int) $user->id === (int) $id;
});
但是我没有从上面看到任何调试信息。
我使用了之前应用中的推送器参数。我想他们一定没问题。否则我会有不同的错误?
在 vue 组件中:
mounted() {
Echo.private(`messages.${this.customerRow.id}`)
.listen('NewMessage', (e) => {
this.hanleIncoming(e.message);
});
我错过了什么?
谢谢!
最佳答案
这个错误的原因是 Laravel 期望 a CSRF token .
你有两个选择:
关于laravel-5 - 如何修复广播身份验证的 419 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55824237/