【问题标题】:I can fire events from Pusher debug console, but Laravel 5.2 isn't firing them我可以从 Pusher 调试控制台触发事件,但 Laravel 5.2 没有触发它们
【发布时间】: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 控制台上没有显示任何内容。
  • 我是说你当地的?
  • 不,我什么都没有,只是没有发生。
  • 可能是您的活动课程中的拼写错误?

标签: laravel-5 events pusher


【解决方案1】:

我的问题是我的 Laravel 版本没有从以前的开发者那里更新。因此,我最初使用的 Pusher 版本与我使用的 Laravel 版本不兼容。我现在已经对此进行了调整,并且可以正常工作。

【讨论】:

    猜你喜欢
    • 2016-07-05
    • 2017-04-17
    • 1970-01-01
    • 2016-06-27
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    相关资源
    最近更新 更多