gpt4 book ai didi

php - 事件不会在 laravel 的 redis 中发布

转载 作者:IT王子 更新时间:2023-10-29 06:13:21 27 4
gpt4 key购买 nike

我想用 laravel echo 和 redis 开发实时应用但它不起作用即:当我触发事件时什么也没发生我检查过 redis 没问题,但我不知道如何解决这个问题

事件:

   class testevent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $data;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
//
$this->data="sdf";

}

/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{

return ['testCh'];
}
}

火:

  Route::get('test',function ()
{
event(new testevent());

return 1;

});


⚠ Starting server in DEV mode...

✔ Running at localhost on port 6001
✔ Channels are ready.
✔ Listening for http events...
✔ Listening for redis events...

Server ready!

js文件:

 import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
console.log("sdfsdffdnpm")
window.Echo.channel('testCh')
.listen('.testevent', () => {
console.log("sooooooooooooooooo");
});

最佳答案

config/app.php make sure you have

     App\Providers\BroadcastServiceProvider::class,

in your .env

  BROADCAST_DRIVER=redis

运行 php artisan queue:listen

希望对你有帮助

关于php - 事件不会在 laravel 的 redis 中发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45000115/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com