F
Filament10mo ago
CT

How to keep both modal Edit action and generate an edit route url?

I have a client who specifically needs both the edit modal and the edit link itself to work (ie modal opens from all table cells), but also needs from other pages a working link to the edit page, ie /{record}/edit should be a valid url. I can get either one working fine, but the problem is as follows:
public static function getPages(): array
{
return [
'index' => Pages\ListSites::route('/'),
'create' => Pages\CreateSite::route('/create'),
'edit' => Pages\EditSite::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListSites::route('/'),
'create' => Pages\CreateSite::route('/create'),
'edit' => Pages\EditSite::route('/{record}/edit'),
];
}
When edit is commented modal works, but there is no edit route generated (verified with php artisan route:list) When edit is uncommented there is no modal but the edit route is correctly generated. Anyone tackled something like this before? Thanks
3 Replies
CT
CTOP10mo ago
So I've made some progress.. it works by keeping the edit page uncommented and having the following:
Tables\Actions\Action::make('edit-modal')
->fillForm(fn (Site $site) => $site->attributesToArray())
->form(static::getFormSchema())
->action(fn (Site $site, $data) => $site->update($data))
Tables\Actions\Action::make('edit-modal')
->fillForm(fn (Site $site) => $site->attributesToArray())
->form(static::getFormSchema())
->action(fn (Site $site, $data) => $site->update($data))
The display/formatting of it is all just single column but it seems to work I guess... trying to figure out now how to fix the formatting
awcodes
awcodes10mo ago
You’re on the right track.
CT
CTOP10mo ago
Ok, anyone looking in the future here you go! The behaviour I have is I now have an edit modal when I click on the row, but we still keep the /{record}/edit route.
$table
->recordUrl(null) // Must be included to disable the default link to the edit page, ie the `/{record}/edit` url
->recordAction('edit-modal')
->actions([
Tables\Actions\Action::make('edit-modal')
->extraAttributes(['class' => 'hidden']) // Can't use ->visible(false) or the modal won't load so have to hide the link with CSS (since we only want click to edit)
->fillForm(fn (Site $site) => $site->attributesToArray())
->form(fn (Form $form) => SiteResource::form($form)->columns(2)) // Columns must be explicitly defined, it doesn't default to 2 for some reason
->action(fn (Site $site, $data) => $site->update($data))
]);
$table
->recordUrl(null) // Must be included to disable the default link to the edit page, ie the `/{record}/edit` url
->recordAction('edit-modal')
->actions([
Tables\Actions\Action::make('edit-modal')
->extraAttributes(['class' => 'hidden']) // Can't use ->visible(false) or the modal won't load so have to hide the link with CSS (since we only want click to edit)
->fillForm(fn (Site $site) => $site->attributesToArray())
->form(fn (Form $form) => SiteResource::form($form)->columns(2)) // Columns must be explicitly defined, it doesn't default to 2 for some reason
->action(fn (Site $site, $data) => $site->update($data))
]);
and also in the resource:
public static function getPages(): array
{
return [
'index' => Pages\ListSites::route('/'),
'create' => Pages\CreateSite::route('/create'),
'edit' => Pages\EditSite::route('/{record}/edit'), // Make sure this is defined
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListSites::route('/'),
'create' => Pages\CreateSite::route('/create'),
'edit' => Pages\EditSite::route('/{record}/edit'), // Make sure this is defined
];
}
Want results from more Discord servers?
Add your server