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
awcodes
awcodes17h ago
What is your code in the observer?
charleswilfriedk
charleswilfriedkOP17h ago
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
awcodes
awcodes17h ago
So where is the notification.
charleswilfriedk
charleswilfriedkOP17h ago
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);
awcodes
awcodes17h ago
Is this side the creating?
charleswilfriedk
charleswilfriedkOP17h ago
The notification is send in the Filament resource On the create action yes
awcodes
awcodes17h ago
The resource has no concept of the model lifecycle. Sorry, just not following the connection based on the code you shared.
charleswilfriedk
charleswilfriedkOP17h ago
Ok i will try to better explain it The notification is send on the action success
awcodes
awcodes17h ago
The create action in the resource has nothing to do with the creating event on the model.
charleswilfriedk
charleswilfriedkOP17h ago
Buit-in in Filament resource I know that but the event is fired by the action right ?
awcodes
awcodes17h ago
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.
charleswilfriedk
charleswilfriedkOP17h ago
Ok i think i will put the logic for the rental_number in the mutateFormDataUsing
awcodes
awcodes17h ago
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.
charleswilfriedk
charleswilfriedkOP17h ago
i get it thx
Want results from more Discord servers?
Add your server