【发布时间】:2020-01-21 14:44:27
【问题描述】:
我能够从 Pusher 调试控制台触发虚拟事件,并且我的客户端能够接收它们。但是当我尝试从我的 UserController 触发事件时,似乎什么也没发生。
这是我的事件类
<?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));
【问题讨论】:
-
你有什么错误吗?
-
我没有收到任何错误消息,我的 Pusher 控制台上没有显示任何内容。
-
我是说你当地的?
-
不,我什么都没有,只是没有发生。
-
可能是您的活动课程中的拼写错误?