Php 如何在使用laravel echo服务器的laravel广播中通过专用通道接收套接字
我使用带有redis/Laravel echo服务器的Laravel 5.7进行广播。 前端是vuejs 目前,公共频道的广播也在发挥作用。 但在专用通道,前端接收插座不工作 下面是我的代码库 此代码部分是用于身份验证的路由代码Php 如何在使用laravel echo服务器的laravel广播中通过专用通道接收套接字,php,laravel,vue.js,socket.io,Php,Laravel,Vue.js,Socket.io,我使用带有redis/Laravel echo服务器的Laravel 5.7进行广播。 前端是vuejs 目前,公共频道的广播也在发挥作用。 但在专用通道,前端接收插座不工作 下面是我的代码库 此代码部分是用于身份验证的路由代码 Broadcast::channel('notification-{id}', function ($user, $id) { return (int) $user->id === (int) $id; }); 这是活动部分 class Notifica
Broadcast::channel('notification-{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
这是活动部分
class NotificationEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public $user;
public function __construct(User $user)
{
//
$this->user = $user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('notification-' . $this->user->id);
}
public function broadcastWith()
{
return ['data' => 'this is message'];
}
}
这是前端代码
//bootstrap.js
window.Echo = new Echo({
broadcaster: "socket.io",
host: window.location.hostname + ":6001"
});
//接收Vue文件
export default {
mounted() {
Echo.private("notification-" + window.Laravel.user).listen(
"NotificationEvent",
e => {
console.log("there");
}
);
}
};
但我无法从拉威尔事件收到任何消息
Route::get('test-broadcast', function () {
$user = \App\User::findOrFail(1);
broadcast(new NotificationEvent($user));
});
[2019-02-22 10:46:28] local.INFO: Broadcasting [App\Events\PrivateNotificationProcedure] on channels [private-notification-procedure-1] with payload:
{
"socket": null
}
我不知道怎么了
谢谢大家运行命令
php-artisan-config:clear
它对我起作用了运行命令
php-artisan-config:clear
它对我有效你有什么解决方案吗?你有什么解决方案吗?