Pet*_*ovo 2 broadcast pusher laravel-5
在我的 Laravel Framework 5.7 / Vuejs 2.6 中,我使用 jwt.auth 并安装 pusher
我检查了我的页面https://imgur.com/a/CveJ6jh 的xsfr 令牌,但我在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];
}
}
Run Code Online (Sandbox Code Playgroud)
在 routes/channels.php 中:
Broadcast::channel('messages.{id}', function ($user, $id) {
dd($user->id, $id);
return (int) $user->id === (int) $id;
});
Run Code Online (Sandbox Code Playgroud)
但我没有从上面看到任何调试信息。
我使用了我之前的应用程序中的推送器参数。我想他们应该没问题。否则我会有不同的错误?
在 vue 组件中:
mounted() {
Echo.private(`messages.${this.customerRow.id}`)
.listen('NewMessage', (e) => {
this.hanleIncoming(e.message);
});
Run Code Online (Sandbox Code Playgroud)
我错过了什么 ?
谢谢!
| 归档时间: |
|
| 查看次数: |
4913 次 |
| 最近记录: |