Answer the question
In order to leave comments, you need to log in
How to properly listen for events in a channel?
Not a very good day, straight to the point, my events are broadcast to the App.User.{id}... channel
using Redis, trying to listen to the event:
$reportJob = (new CreateReport($dataType, $dataTypeContent, $request->get('excel')))
->onConnection('redis')
->delay(Carbon::now()->addMinutes(1));
qYgR8k5XDQETRBtlAAAM joined channel: private-App.User.1
Channel: opencrm_database_private-App.User.1
Event: report.created
Echo.private(`App.User.{{ auth()->user()->id }}`)
.listen('.report.created', (e) => {
console.log(e);
});
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\BroadcastMessage;
class ReportCreated extends Notification implements ShouldQueue
{
use Queueable;
public $report_link;
public function __construct($report_link)
{
$this->report_link = $report_link;
}
public function via($notifiable)
{
return ['database'];
}
public function toArray($notifiable)
{
return [
'report_link' => $this->report_link
];
}
}
Answer the question
In order to leave comments, you need to log in
Guys, I'm closing the question, the problem was in the names of the channels. I thought that the server adds prefixes to channels only in the log.
With public channel and js:
Echo.channel(`opencrm_database_App.User.{{ auth()->user()->id }}`)
.listen('AppCreateReport', (e) => {
console.log(e);
}).notification((notification) => {
console.log(notification);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question