vendredi 20 septembre 2019

I can fire events from Pusher debug console, but Laravel 5.2 isn't firing them

I am able to fire dummy events from the Pusher debug console and my client side is able to pick them up. But when I try to fire the event from my UserController nothing seems to happen.

Here is my Event 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];
    }
}


Here is my listener, which doesn't have anything because I want everything to be process client side

<?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)
    {
        //
    }
}

Here is my .env

BROADCAST_DRIVER=pusher
PUSHER_APP_ID=858577
PUSHER_APP_KEY=ec160cc0a1ca15e463f4
PUSHER_APP_SECRET=5a9e0a561059593db569
QUEUE_DRIVER=sync 

Here is my event service provider

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        'App\Events\NewPurchase' => [
            'App\Listeners\NewPurchaseListener',
        ],
    ];

And here is where the event is fired

 Event::fire(new NewPurchase($product));



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire