phplaravelpusher

laravel event not send to pusher


i have pusher app, then i try to send message to pusher by laravel event, this is my event :

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class NewOrder
{
    use Dispatchable, InteractsWithSockets, SerializesModels;
    public $email;
    public $message;


    public function __construct($email)
    {
        $this->email = $email;
        $this->message = "New order from {$email}, please check.";
        //
    }

    public function broadcastOn()
    {
        return ['new-order'];
    }

}

and i try to test it with route test,

Route::get('test', function () {
    event(new App\Events\NewOrder('John'));
    return "Event has been sent!";
});

my pusher configuration have been configured like my pusher's account configuration, but after access /test , the pusher debug console doesn't show anything.

enter image description here this is my broadcasting.php

    'default' => env('BROADCAST_DRIVER', 'pusher'),


    'connections' => [

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                // 'cluster' => 'ap1',
                'encrypted' => true,
            ],
        ],

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],

        'log' => [
            'driver' => 'log',
        ],

        'null' => [
            'driver' => 'null',
        ],

    ],

];

i don't know to see pusher's log from laravel app, anyone can help me? i'm using laravel 5.5


Solution

  • I think the problem is with your event class declaration, you should implement ShouldBroadcastNow as it fires the event immediately and doesn't require queue implementation. By default you need to set up a queue and then run that queue to fire events.

    use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
    class NewOrder implements ShouldBroadcastNow
    {
      ....do your stuff....
    }
    

    And also checkout this amazing playlist, this will solve your all problems for sure