I'm using Laravel 5.3 with Pusher and all is working well.
However I would like to export my Pusher credentials to .env
. Or anywhere else so that I can easily use different Pusher apps on my dev/staging/production environments.
This is my setup:
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'myKey', //development key
cluster: 'eu',
encrypted: true
});
In gulpfile.js
I have
elixir(function(mix) {
mix.webpack('echo.js','./resources/assets/js/');
});
then
mix.scripts([
'echo.js',
...
], 'public/js/all.js');
And finally in my view:
let myRoom = 'room-user-'+'{{ Auth::user()->id }}';
Echo.private(myRoom)
.listen('MyEvent', (e) => {
console.log(e);
});
As I said this is all working well.
My problem is the key: 'myKey', //development key
. Is there a simple way to use Laravel environment variable env('PUSHER_KEY')
here? Because as things are now I need to use the same Pusher App in my development, staging and production.
Also my config/broadcasting
is
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_CLUSTER','eu'),
'encrypted' => true,
],
],