2

I get "Illuminate\Broadcasting\BroadcastException" when trying to broadcast event. I've checked my .env file - it's set correctly, I'm on localhost so I set 'encrypted' to false aswell, BroadcastServiceProvider is uncommented. Nothing helps.

FULL ERROR IMAGE

bootstrap.js

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
   broadcaster: 'pusher',
   key: '***',
   cluster: 'mt1',
   encrypted: false
});

web.php

Route::post('/messages', function() {
$user = Auth::user();

$message = $user->messages()->create([
    'message' => request()->get('message')
]);

broadcast(new MessagePosted($message, $user))->toOthers();

return ['status' => 'OK'];
})->middleware('auth');

broadcasting.php

'pusher' => [
   'driver' => 'pusher',
   'key' => env('PUSHER_APP_KEY'),
   'secret' => env('PUSHER_APP_SECRET'),
   'app_id' => env('PUSHER_APP_ID'),
   'options' => [
      'cluster' => env('PUSHER_APP_CLUSTER'),
      'encrypted' => false,
   ],
],
Nicolas
  • 33
  • 1
  • 5
  • Please share the full error, not just the name of the Exception. A copy of the stacktrace included in your question, or a screenshot, would be appreciated. Thank you. – sam Jan 29 '18 at 00:31
  • As a quick follow up, the only place `BroadcastException` is thrown is [here](https://github.com/laravel/framework/blob/5.5/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php#L107) which is when there's an error connecting to pusher so the problem is almost certainly with your configuration. Have you confirmed that `PUSHER_APP_KEY`, `PUSHER_APP_SECRET`, `PUSHER_APP_ID` and `PUSHER_APP_CLUSTER` are accurate? – sam Jan 29 '18 at 00:33
  • @sam thank you. Added. – Nicolas Jan 29 '18 at 00:34
  • @sam re-checked it almost probabbly close to 50 times by now. I am sure they are accurate. – Nicolas Jan 29 '18 at 00:36
  • From the command line start tinker (`php artisan tinker`) then enter the following `Config::get('broadcasting.connections.pusher');` and check that the values are all exactly as you expect: no trailing spaces/characters. Ensure that you haven't got your key/secret/id mixed up. – sam Jan 29 '18 at 00:39
  • 3
    @sam Thank you. I dont know why but somehow the settings received from this command were different. I did php artisan config:clear and then the real one were set. Thank you very much, was struggling with this a long time. – Nicolas Jan 29 '18 at 00:46

1 Answers1

2

if your working on localhost try setting your .env file

set

APP_URL=http://localhost

DB_HOST=localhost

and run

php artisan config:cache

hope this helps you :)

Franz
  • 354
  • 1
  • 4
  • 15