Notification send before observer creating function is executed
Hello everyone!
I have an observer on my model to make un order number during the creating event, but the notification which is suppose to include the order number is send without it (i suppose that the order number is not yet ready when the notification is send)
Does anyone have any idea how to correct this behaviour ?
14 Replies
What is your code in the observer?
public function creating(Rental $rental): void
{
....
$rental->rental_number = 'NKH-' . now()->format('Y') . mb_str_pad((string) $rental->order, 5, '0', STR_PAD_LEFT);
}
I'm trying to include that rental_number in the notification. It works everywhere else but not on the create action
So where is the notification.
Notification::make()
->success()
->icon('heroicon-m-link')
->title(('filament-resources.notification.rental.update-car-driver.title'))
->body(('filament-resources.notification.rental.update-car-driver.success', ['rental' => $record->rental_number]))
->send()
->sendToDatabase(User::getNotifiableFor(RentalPermissions::NOTIFIED_UPDATED->value), isEventDispatched: true);
Is this side the creating?
The notification is send in the Filament resource
On the create action yes
The resource has no concept of the model lifecycle.
Sorry, just not following the connection based on the code you shared.
Ok i will try to better explain it
The notification is send on the action success
The create action in the resource has nothing to do with the creating event on the model.
Buit-in in Filament resource
I know that but the event is fired by the action right ?
Ok, but the resource has nothing to do with observers. Just trying to tie them together in my mind.
No, observers are fired by the model.
The action can create or update a model. But the observer is fired by the model. It’s an indirect relation of causality.
Ok i think i will put the logic for the rental_number in the mutateFormDataUsing
Ie, action creates record, then observer says record was created so also do this.
They aren’t mutually exclusive
Nor, are they the same thing. If that makes sense.
i get it thx