Laravel Pusher例外:“Illuminate \ Broadcasting \ BroadcastException”

时间:2018-01-29 00:26:37

标签: laravel events echo pusher broadcasting

尝试广播事件时,我得到“Illuminate \ Broadcasting \ BroadcastException”。我检查了我的.env文件 - 它设置正确,我在localhost上,所以我将'encrypted'设置为false,以及BroadcastServiceProvider取消注释。什么都没有帮助。

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 个答案:

答案 0 :(得分:0)

如果您在本地主机上工作,请尝试设置.env文件

设置

APP_URL=http://localhost

DB_HOST=localhost

并运行

php artisan config:cache

希望这对您有帮助:)