Form action - save and load next record -

Is it possible to have a form action that saves the current and loads the next (filtered) record of a resource for editing?
Solution:
override getFormActions() in the EditPage ```php protected function getFormActions(): array {...
Jump to solution
2 Replies
Solution
LeandroFerreira
LeandroFerreira7mo ago
override getFormActions() in the EditPage
protected function getFormActions(): array
{
return [
...parent::getFormActions(),
Actions\Action::make('saveAndNext')
->action(function () {

$nextRecord = $this
->getRecord()
->where('id', '>', $this->getRecord()->id)
->orderBy('id', 'asc')
->first();

$this->save();

redirect(static::getResource()::getUrl('edit', ['record' => $nextRecord]));
}),
];
}
protected function getFormActions(): array
{
return [
...parent::getFormActions(),
Actions\Action::make('saveAndNext')
->action(function () {

$nextRecord = $this
->getRecord()
->where('id', '>', $this->getRecord()->id)
->orderBy('id', 'asc')
->first();

$this->save();

redirect(static::getResource()::getUrl('edit', ['record' => $nextRecord]));
}),
];
}
WishDasher
WishDasherOP7mo ago
Thx.
Want results from more Discord servers?
Add your server