@blackrockshooter Have you updated your pusher credentials on your server's env file?
Laravel Pusher not working on Hostinger
I've setup broadcasting as pusher and also provided the right app id, key, secret, and cluster. I made a new notification called AppointmentUpdatedNotification and it implements ShouldBroadcastNow interface and change some of its methods:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class AppointmentUpdatedNotification extends Notification implements ShouldBroadcastNow
{
use Queueable;
public string $user_id;
public string $patient_id;
public string $appointment_id;
public string $doctor_id;
/**
* Create a new notification instance.
*/
public function __construct(
string $user_id,
string $patient_id,
string $appointment_id,
string $doctor_id
)
{
$this->user_id = $user_id;
$this->patient_id = $patient_id;
$this->appointment_id = $appointment_id;
$this->doctor_id = $doctor_id;
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['broadcast'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the broadcast representation of the notification.
*
* @param object $notifiable
* @return BroadcastMessage
*/
public function toBroadcast(object $notifiable): BroadcastMessage
{
return new BroadcastMessage([
'user' => $this->user_id,
'patient' => $this->patient_id,
'appointment' => $this->appointment_id,
'doctor' => $this->doctor_id,
]);
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
//
];
}
}
And in livewire at the patient side I notify the doctor through this method:
protected function sendAppointmentUpdateNotification($appointment_id, $doctor_id): void
{
// Sends a new appointment notification to the doctor
Doctor::firstWhere('id', $doctor_id)
->user
->notify(new AppointmentUpdatedNotification(
auth()->user()->id,
auth()->user()->patient->id,
$appointment_id,
$doctor_id
));
}
And at the doctor's side which also uses livewire, I refresh through making the render method listen to the notification using Livewire\Attributes\On:
#[On('echo-private:users.{auth_user_id},.Illuminate\Notifications\Events\BroadcastNotificationCreated')]
public function render()
It works on localhost but when I deploy it on hostinger pusher just doesnt work and I cant see any connection made in debug console of pusher.
Finally solved the problem... The problem was composer update didn't update the livewire in hostinger because I need to update it using composer2 update and it now works.
Please or to participate in this conversation.
