Reputation: 6088
I can't see, to find out why broadcastOn() is not triggering. Here is my code:
<?php
namespace App\Events;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class NotificationEvent extends Event implements ShouldBroadcast{
use SerializesModels;
/**
* Create a new event instance.
*
* @return void
*/
public $message;
public $user;
public function __construct($user_id,$message){
$this->user = $user_id;
$this->message = $message;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
//var_dump("Sending event to:".'userNotifications.'.$this->user_id);
//return ['userNotifications.'.$this->user_id];
\Log::info("broadcast notification");
\Log::info($this->message);
return ['notifications'];
}
}
Logging in the _construct works, but the logging in broadcastOn() does not work.
My .env file is set to redis, Redis server is on and listening on port 3001.
Does anyone know why this might now work?
Upvotes: 0
Views: 1016
Reputation: 3525
The actual broadcast is a Job. Look in your Laravel job queue. When the job executes via php artisan queue:work
then the broadcastOn()
method will fire.
Upvotes: 3