1

我想用 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");
});
4

1 回答 1

1

config/app.php 确保你有

     App\Providers\BroadcastServiceProvider::class,

在你的 .env 中

  BROADCAST_DRIVER=redis

php artisan queue:listen

我希望这有帮助

于 2017-07-09T20:01:55.040 回答