本文介绍了Laravel Pusher例外:"Illuminate \ Broadcasting \ BroadcastException"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试广播事件时,我收到"Illuminate \ Broadcasting \ BroadcastException".我检查了我的.env文件-设置正确,我在localhost上,所以我也将'encrypted'设置为false,BroadcastServiceProvider未注释.没有任何帮助.

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.

完整错误图像

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,
   ],
],

推荐答案

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

if your working on localhost try setting your .env file

设置

APP_URL=http://localhost

DB_HOST=localhost

并运行

php artisan config:cache

希望这对您有帮助:)

这篇关于Laravel Pusher例外:"Illuminate \ Broadcasting \ BroadcastException"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 14:34