I have an 403 forbidden error when using pusher, everything looks correct but I still face this error!
After the user create the order a new notification should be created:
$order->doctor->user->notify(new AppointmentNotification($checkOrder, $user));
in the AppointmentNotification file:
public function via(object $notifiable): array
{
return ['broadcast'];
}
public function toBroadcast($notifiable)
{
return new BroadcastMessage([
'title' => 'Appointment Reservation',
'body' => 'New Appointment Reservation!',
'icon' => 'fadeIn animated bx bx-health',
'url' => route('doctor.appointments'),
'doctorId' => $notifiable->id,
]);
}
The channel:
Broadcast::channel('Models.User.{doctorId}', function ($user, $doctorId) {
return (int) $user->id === (int) $doctorId;
});
The bootstrap and js files countains:
window.Echo = new Echo({
broadcaster: 'pusher',
key: import.meta.env.VITE_PUSHER_APP_KEY,
cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1',
wsHost: import.meta.env.VITE_PUSHER_HOST ? import.meta.env.VITE_PUSHER_HOST : `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`,
wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80,
wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443,
forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https',
enabledTransports: ['ws', 'wss'],
});
window.Echo.private(`App.Models.User.${doctorId}`)
.notification(function(data){
alert(data.body)
})
And finally Im defining the doctorId in the layout and calling the Js file:
<script>
const doctorId = "{{ optional(Auth::user()->doctor)->user_id }}";
</script>
<script>
{!! Vite::content('resources/js/app.js') !!}
</script>
Everything looks correct, I need you help, thanks.
I have tried to create event, and I faced the same error!