How to add $record and $ownerRecord in a relation manager notification

Hi everyone! I'm trying to add the record and the owner record name in the success notification on the create action. This is what i tried but it's not working. Notification::make()->success() ->title( fn (RelationManager $livewire, Model $record) => "{$record->name} successfully added to {$livewire->ownerRecord->name}." )
8 Replies
nostrodamned
nostrodamned15mo ago
would it not be fn (Model $record) rather than livewire? something like fn (Status $record): string =>
substr($record->name).....
charleswilfriedk
charleswilfriedkOP15mo ago
Inside a relation manager you have two record: - RelationManager $livewire->ownerRecord give you access to the owner record - Model $record is the pivot record I can use it fine like that to customize the header but it's not working when i try to change the success notification body
dissto
dissto15mo ago
Your code snippet above is missing the ->send() method though.
Notification::make()->success()
->title( fn (RelationManager $livewire, Model $record) => "{$record->name} successfully added to {$livewire->ownerRecord->name}." )->send()
Notification::make()->success()
->title( fn (RelationManager $livewire, Model $record) => "{$record->name} successfully added to {$livewire->ownerRecord->name}." )->send()
charleswilfriedk
charleswilfriedkOP15mo ago
It’s inside a successNotification so I just have to specify the notification
cheesegrits
cheesegrits15mo ago
@charleswilfriedk can you show your whole action code? I suspect you may need to get what you need from an outer closure, rather than the one on the notification. So like ...
CreateAction::make()
->successNotification(function ($livewire, $record) {
Notification::make()
->success()
->title(fn () => "{$record->name} successfully added to {$livewire->ownerRecord->name}." )
->send();
})
CreateAction::make()
->successNotification(function ($livewire, $record) {
Notification::make()
->success()
->title(fn () => "{$record->name} successfully added to {$livewire->ownerRecord->name}." )
->send();
})
charleswilfriedk
charleswilfriedkOP15mo ago
Maybe My code right now is like that AttachAction::make() ->modalHeading( fn (RelationManager $livewire) => "Attach a role to user {$livewire->ownerRecord->name}" ) ->successNotification( Notification::make() ->success() ->title( fn (RelationManager $livewire, Model $record) => "The role {$record->name} was successfully attached to the user {$livewire->ownerRecord->name}." ) ) Let me try your solution AttachAction::make() ->modalHeading( fn (RelationManager $livewire) => "Attach a role to user {$livewire->ownerRecord->name}" ) ->successNotification(function (RelationManager $livewire, Model $record) { return Notification::make() ->success() ->title("The role {$record->name} was successfully attached to the user {$livewire->ownerRecord->name}."); }) It's working!! Thx
cheesegrits
cheesegrits15mo ago
Yup. The Notification callbacks don't know anything about relation managers. As per that discussion you tagged me in, the parameters available in a callback closure are very context dependent.
charleswilfriedk
charleswilfriedkOP15mo ago
I get it now
Want results from more Discord servers?
Add your server