Notification?

Hi, I'm trying to use notifications from laravel in my panel. This is my call: $order->mechanic->notify(new OrderAssigned($order, Auth::user())); As you can see, i have an OrderAssigned which extends a Notification. How can I use this to send a notification in filament? Is this even possible?
10 Replies
Fr34k
Fr34kOP3w ago
I read that but didnt understand it or didnt get it working. To understand. In my OrderAssigned Notification class I create the toDatabase method? If yes, I receive this: Declaration of OrderAssigned::toDatabase(User $notifiable): array must be compatible with Notification::toDatabase(): \Filament\Notifications\DatabaseNotificationPHP(PHP2439)
toeknee
toeknee3w ago
Yes that is correct, you get that error because you did OrderAssigned not User. You need to do: Notification::toDatabase(Auth::user())
Fr34k
Fr34kOP3w ago
But I dont want to send the notification to the current user? I want to send it to a specific user
toeknee
toeknee3w ago
So get the specific user? Notification::toDatabase(User::find(1)); If you have a relationship on the model: Notication::toDatabase($order->creator);
Fr34k
Fr34kOP3w ago
Wait but so far I used $this->mechanic->notify(new OrderAssigned($this, Auth::user())); How should it look now? I just add a toDatabase Method in the OrderAssigned Notification and call the ->toDatabase?
toeknee
toeknee3w ago
Ok so I believe OrderAssigned you have extended Filament\Notifications\Notification, so then you need to do
$this->mechanic->notify(
OrderAssigned($this, Auth::user())
->toDatabase()
);
$this->mechanic->notify(
OrderAssigned($this, Auth::user())
->toDatabase()
);
Fr34k
Fr34kOP3w ago
Nice, ill give it a try - thank you so much!
toeknee
toeknee3w ago
No problem the other Option is:
OrderAssigned::make()
->title('Saved successfully')
->sendToDatabase($this->mechanic);
OrderAssigned::make()
->title('Saved successfully')
->sendToDatabase($this->mechanic);
just FYI assigning the type helps so: OrderAssignedNotification instead of OrderAssigned. Makes it more readable
Fr34k
Fr34kOP2w ago
This worked, thanks!

Did you find this page helpful?