问题
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,
],
],
回答1:
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 :)
来源:https://stackoverflow.com/questions/48492853/laravel-pusher-exception-illuminate-broadcasting-broadcastexception