1

Here is my .env code->

BROADCAST_DRIVER=pusher
PUSHER_APP_ID=xxxxx
PUSHER_APP_KEY=xxxxx
PUSHER_APP_SECRET=xxxxx
PUSHER_APP_CLUSTER=xxxxx

Here is my config code ->

 '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'),
                'useTLS' => true,
                'encrypted' => true,
            ],
        ],

Here is my event code ->

<?php

namespace App\Events;


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

class orderEvent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public $text;

    public function __construct($text)
    {
        $this->text = $text;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('fish20');
    }
}

and finally here is my route for testing from which i trigger the event but nothing actually happens :( . ->

Route::get('/get', function () {
    $text = 'New order received.';
    event(new orderEvent($text));
});

I cannot see any event triggered on debug console of my pusher channel.

  • In your get route, swap out the event request for dd("test: $text"); Does it show up on screen? – Delmontee Sep 06 '21 at 10:01
  • Of course it does and i think that dosent have anything to do with the event trigger because whatever data i send in it should trigger the event and i should see it on my debug console right? – thestackyuser32 Sep 06 '21 at 15:16

2 Answers2

2

I got the solution. for some reason laravel uses Queue in events and my queue connection was database so like this -> QUEUE_CONNECTION=database and i removed that and made it sync so that it gets trigger and dosent queue it for later like this -> QUEUE_CONNECTION=sync

Also there is another way on your event file instead of ShouldBroadcast use this -> ShouldBroadcastNow

1

You should use broadcast(new orderEvent($text)); instead of event(new orderEvent($text)); in your route.

Ehsan A. Kian
  • 169
  • 1
  • 3
  • 9