Reputation: 71
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.
Upvotes: 1
Views: 2218
Reputation: 190
If you are using QUEUE_CONNECTION=database please remove it & use QUEUE_CONNECTION=sync. then event triggering part will work.
Because i already implemented chat app using vuejs + laravel + pusher. app worked perfectly. but i added mail sending process using queue job. so i changed queue connection as a database. finally my chat app doesnt work. so i removed queue connecton as a sync. now pusher event is working perfectly
Upvotes: 0
Reputation: 71
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
Upvotes: 5
Reputation: 281
You should use broadcast(new orderEvent($text));
instead of event(new orderEvent($text));
in your route.
Upvotes: 1