【发布时间】:2016-09-08 19:25:04
【问题描述】:
我的应用程序出现了非常不寻常的广播问题,我通过 Dropbox 同步了它,在我的笔记本电脑上我可以运行它并将事件发送到推送服务器,但是在我的桌面上它没有。我使用相同版本的 XAMPP 服务器,相同的迁移等。有人可以提出任何建议吗?下面提供了代码。
App\Events\TodoCreated.php
<?php
namespace App\Events;
use App\Models\Todo;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class TodoCreated extends Event implements ShouldBroadcast
{
use InteractsWithSockets, SerializesModels;
public $todo;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Todo $todo)
{
$this->todo = $todo;
}
/*public function broadcastWith()
{
}*/
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return ['team.' . $this->todo->team_id . '.todos'];
}
}
config/broadcasting.php
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'eu',
'encrypted' => true
],
],
.env
BROADCAST_DRIVER=pusher
...
PUSHER_APP_ID=<app_id>
PUSHER_KEY=<key>
PUSHER_SECRET=<secret>
- 我使用
event(new App\Events\TodoCreate($todo))触发事件,其中$todo是App\Models\Todo的一个实例 - 我在 config/app.php 文件中启用了 BroadcastServiceProvider
- 我运行
php artisan queue:work --timeout=0并看到事件已注册并成功运行,但在我的推送调试面板上没有收到任何内容
【问题讨论】:
标签: php laravel pusher laravel-5.3