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
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)
Yes that is correct, you get that error because you did OrderAssigned not User. You need to do:
Notification::toDatabase(Auth::user())
But I dont want to send the notification to the current user? I want to send it to a specific user
So get the specific user?
Notification::toDatabase(User::find(1));
If you have a relationship on the model:
Notication::toDatabase($order->creator);
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?
Ok so I believe OrderAssigned you have extended Filament\Notifications\Notification, so then you need to do
Nice, ill give it a try - thank you so much!
No problem the other Option is:
just FYI assigning the type helps so: OrderAssignedNotification instead of OrderAssigned. Makes it more readable
This worked, thanks!