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?
getFormActions()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]));
}),
];
}