几个小时以来,我一直在尝试在我的laravel应用程序中使用pusher。为此,我遵循了一些教程,但它仍然不起作用,现在我神经崩溃了。
这是我的代码:
.env
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=*ID
PUSHER_APP_KEY=*KEY
PUSHER_APP_SECRET=*SECRET
PUSHER_APP_CLUSTER=eu
测试事件
<?php
namespace AppEvents;
use AppWish;
use IlluminateBroadcastingChannel;
use IlluminateQueueSerializesModels;
use IlluminateBroadcastingPrivateChannel;
use IlluminateBroadcastingPresenceChannel;
use IlluminateFoundationEventsDispatchable;
use IlluminateBroadcastingInteractsWithSockets;
use IlluminateContractsBroadcastingShouldBroadcast;
class TestEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct()
{
}
/**
* Get the channels the event should broadcast on.
*
* @return IlluminateBroadcastingChannel|array
*/
public function broadcastOn()
{
return new Channel('tests');
}
}
web.php
Route::get('/send-test', function(){
event(new TestEvent());
return ['message' => 'OK?'];
});
我做错了什么?谢谢你的帮助。
由于Laravel太大了,很难确切知道出了什么问题,但这里有一个检查表。
- 您是否已将
.env
文件中的广播驱动程序更改为pusher - 你运行过
composer require pusher/pusher-php-server
吗 - 您是否使用
npm run dev
编译了Javascript依赖项 - 您是否已将凭据添加到
.env
文件中 -
您是否已将集群添加到config/broadcasting.php中的pusher区域的选项部分?你这样做:
"选项"=>["cluster"=>"eu","加密"=>true],
-
您是否取消了config/App.php中以下行的注释?
应用程序\提供商\广播服务提供商
如果以上都不起作用,我个人可以建议你尝试这个教程吗?我已经亲自测试过这个教程,它应该起作用。https://blog.pusher.com/how-to-build-a-laravel-chat-app-with-pusher/.
让我知道你进展如何。