我可以从 Pusher 调试控制台触发事件,但 Laravel 5.2 没有触发它们
I can fire events from Pusher debug console, but Laravel 5.2 isn't firing them
我能够从 Pusher 调试控制台触发虚拟事件,并且我的客户端能够接收到它们。但是当我尝试从我的 UserController 触发事件时,似乎什么也没有发生。
这是我的活动 class
<?php
namespace App\Events;
use App\Events\Event;
use App\Player;
use App\Product;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NewPurchase extends Event implements ShouldBroadcast
{
use SerializesModels;
public $product;
/**
* Create a new event instance.
*
* @param Product $product
* @return void
*/
public function __construct(Product $product)
{
$this->product = $product;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return [Player::where('user_id', $this->product->seller_id)->first()->group_id];
}
}
这是我的侦听器,它没有任何内容,因为我希望一切都在客户端进行处理
<?php
namespace App\Listeners;
use App\Events\NewPurchase;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class NewPurchaseListener implements ShouldQueue
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param NewPurchase $event
* @return void
*/
public function handle(NewPurchase $event)
{
//
}
}
这是我的 .env
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=858577
PUSHER_APP_KEY=ec160cc0a1ca15e463f4
PUSHER_APP_SECRET=
QUEUE_DRIVER=sync
这是我的活动服务提供商
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\NewPurchase' => [
'App\Listeners\NewPurchaseListener',
],
];
这里是触发事件的地方
Event::fire(new NewPurchase($product));
我的问题是我的 Laravel 版本没有从以前的开发者那里得到更新。因此,一开始我使用的 Pusher 版本与我使用的 Laravel 版本不兼容。我现在已经对此进行了调整,并且可以正常工作。
我能够从 Pusher 调试控制台触发虚拟事件,并且我的客户端能够接收到它们。但是当我尝试从我的 UserController 触发事件时,似乎什么也没有发生。
这是我的活动 class
<?php
namespace App\Events;
use App\Events\Event;
use App\Player;
use App\Product;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NewPurchase extends Event implements ShouldBroadcast
{
use SerializesModels;
public $product;
/**
* Create a new event instance.
*
* @param Product $product
* @return void
*/
public function __construct(Product $product)
{
$this->product = $product;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return [Player::where('user_id', $this->product->seller_id)->first()->group_id];
}
}
这是我的侦听器,它没有任何内容,因为我希望一切都在客户端进行处理
<?php
namespace App\Listeners;
use App\Events\NewPurchase;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class NewPurchaseListener implements ShouldQueue
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param NewPurchase $event
* @return void
*/
public function handle(NewPurchase $event)
{
//
}
}
这是我的 .env
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=858577
PUSHER_APP_KEY=ec160cc0a1ca15e463f4
PUSHER_APP_SECRET=
QUEUE_DRIVER=sync
这是我的活动服务提供商
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\NewPurchase' => [
'App\Listeners\NewPurchaseListener',
],
];
这里是触发事件的地方
Event::fire(new NewPurchase($product));
我的问题是我的 Laravel 版本没有从以前的开发者那里得到更新。因此,一开始我使用的 Pusher 版本与我使用的 Laravel 版本不兼容。我现在已经对此进行了调整,并且可以正常工作。