几个小时以来,我一直在尝试在laravel应用中使用pusher。为此,我正在关注一些教程,但是它仍然无法正常工作,现在我很紧张。
这是我的代码:
.env
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=*ID
PUSHER_APP_KEY=*KEY
PUSHER_APP_SECRET=*SECRET
PUSHER_APP_CLUSTER=eu
TestEvent
<?php
namespace App\Events;
use App\Wish;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
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 \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('tests');
}
}
web.php
Route::get('/send-test', function(){
event(new TestEvent());
return ['message' => 'OK?'];
});
我在做什么错?谢谢您的帮助。
答案 0 :(得分:4)
由于Laravel太大,因此很难确切知道出了什么问题,但这是清单。
.env
文件中的广播驱动程序更改为pusher?composer require pusher/pusher-php-server
吗?npm run dev
编译了Javascript依赖项?.env
文件中? 您是否已将集群添加到config / broadcasting.php中pusher区域的options部分?您可以这样操作:
'options'=> [ '集群'=>'欧盟', '已加密'=> true ]
您是否已取消注释config / App.php中的以下行?
App \ Providers \ BroadcastServiceProvider
如果以上方法均无效,我个人可以建议您尝试本教程-我已经亲自测试了该教程,它应该可以工作。 https://blog.pusher.com/how-to-build-a-laravel-chat-app-with-pusher/。
让我知道你过得怎么样。