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
nostrodamned10mo ago
would it not be fn (Model $record) rather than livewire? something like fn (Status $record): string =>
substr($record->name).....
charleswilfriedk
charleswilfriedk10mo 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
dissto10mo 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
charleswilfriedk10mo ago
It’s inside a successNotification so I just have to specify the notification
cheesegrits
cheesegrits10mo 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
charleswilfriedk10mo 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
cheesegrits10mo 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
charleswilfriedk10mo ago
I get it now
Want results from more Discord servers?
Add your server
More Posts
Title in repeaterJust wondering if there is a way to display a title in repeater when it is collapsed?Idea for Filament: autopopulate label/description/icon/... of table/form/infolist/NotifHello all, I have an idea for the core (I don't know how to implement it as plugin. Maybe macro ?).I can view two models in one ResourcesI have two models one survey and another one is user info. I want to create one table with a survey Visible and Hidden are not working on NavigationItem in NavigationBuilder arrayFor some reason, neither `hidden()` nor `visible()` is working! ```php public function panel(Panel $Check for uniqueness according to column title for grouped recordsHi I am trying to check for uniqueness of a Status Title - based on the model type. This is my code Read data into repeater based on selected filedthere is a products table with mark_id if i chose the mark_id i want to fill all the products with tBug in colorPicker in modalWhen the colorpicker is in a modal (editRecord) it is pretty unusable, you cant slide the color bar Make default select option other than the disabled optionhow to make a default option other than the disabled option. ```php Select::make('status') ->optHow to Set Grouped Rows as collapsed by defaultHi all again!! I have collapsible grouped rows on a table - how can we set them to be collapsed by dSQLSTATE[HY000]: General error: 1364 Field 'guardian_id' doesn't have a default valueI have a StudentResource and in form I am doing this: ```php Forms\Components\Select::make('guardian