Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't remove laravel_database_ prefix from channel

I'm setting up Laravel echo to broadcast events. But whenever I try to broadcast to a channel the channel name gets an automatic prefix: 'laravel_database_'

I've tried switching the return inside the Event to a regular 'Chanel' as following:

public function broadcastOn()
{
return new Channel('public');
}

but when I look into the laravel-echo-server logs I see it is still being broadcasted on: 'laravel_database_public'.

This way I would need to do the following in my JS:

Echo.channel('laravel_database_public').listen('MessageSent', ({message}) => {
                console.log(message);
            });

But ofcourse, I want to remove the prefix (or figure out why its there). Hopefully someone can clear this up for me. Thanks in advance.

like image 200
Jesse Vlietveld Avatar asked Jan 26 '23 00:01

Jesse Vlietveld


2 Answers

This is configurable in config/database.php (and I believe even removable) under

'redis' => [
    'options' => [
        'prefix' => // change here.
    ]
]
like image 100
Alex Harris Avatar answered Jan 29 '23 16:01

Alex Harris


The accepted answer does not work with laravel-echo-server.

The solution is rather to let the whole Redis Laravel config untouched and to run version ^1.6.0 of laravel-echo-server with the proper keyPrefix option in laravel-echo-server.json config file:

{
   "databaseConfig": {
     "redis": {
       "keyPrefix": "laravel_database_"
      }
  }
}

Source

like image 39
eightyfive Avatar answered Jan 29 '23 15:01

eightyfive