© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
7 replies
ndevfr

Is it possible to add "Previous" and "Next" buttons on Form ?

Hello, I want buttons to go to previous record or next record when I am editing one ?
Is it possible ?
Solution
This will do what you're asking

class EditTask extends EditRecord
{
    protected static string $resource = TaskResource::class;

    protected function getHeaderActions(): array
    {
        $nextRecord = $this->getNewRecord(true);
        $prevRecord = $this->getNewRecord(false);

        return [
            DeleteAction::make(),
            Action::make('next')
                ->url($nextRecord ? TaskResource::getUrl('edit', ['record' => $nextRecord->getKey()]) : '#')
                ->disabled(!$nextRecord),
            Action::make('previous')
                ->url($prevRecord ? TaskResource::getUrl('edit', ['record' => $prevRecord->getKey()]) : '#')
                ->disabled(!$prevRecord),
        ];
    }

    protected function getNewRecord(bool $nextRecord){
        $currentRecord = $this->getRecord();
        if (!$currentRecord) {
            return null;
        }

        $record = null;
        if ($nextRecord){
            $record = $currentRecord->where('id', '>', $currentRecord->getKey());
        }else{
            $record = $currentRecord->where('id', '<', $currentRecord->getKey())->orderBy('id', 'desc');
        }
        return $record->first();
    }
}
class EditTask extends EditRecord
{
    protected static string $resource = TaskResource::class;

    protected function getHeaderActions(): array
    {
        $nextRecord = $this->getNewRecord(true);
        $prevRecord = $this->getNewRecord(false);

        return [
            DeleteAction::make(),
            Action::make('next')
                ->url($nextRecord ? TaskResource::getUrl('edit', ['record' => $nextRecord->getKey()]) : '#')
                ->disabled(!$nextRecord),
            Action::make('previous')
                ->url($prevRecord ? TaskResource::getUrl('edit', ['record' => $prevRecord->getKey()]) : '#')
                ->disabled(!$prevRecord),
        ];
    }

    protected function getNewRecord(bool $nextRecord){
        $currentRecord = $this->getRecord();
        if (!$currentRecord) {
            return null;
        }

        $record = null;
        if ($nextRecord){
            $record = $currentRecord->where('id', '>', $currentRecord->getKey());
        }else{
            $record = $currentRecord->where('id', '<', $currentRecord->getKey())->orderBy('id', 'desc');
        }
        return $record->first();
    }
}
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Can wizard next and previous buttons on form trigger save method?
FilamentFFilament / ❓┊help
15mo ago
Is it possible to get form from resource and add it to createOptionForm?
FilamentFFilament / ❓┊help
3y ago
Wizard Form disable next/previous
FilamentFFilament / ❓┊help
16mo ago
Is it possible to add navigation on top?
FilamentFFilament / ❓┊help
3y ago