© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
13 replies
Sauravisus

DefaultSort on a Repeater

I've been searching high and low, but couldn't find an answer to this. Is there a way to decide the sorting order for items in a repeater?

This is my repeater and its components:

Repeater::make('notes')
    ->relationship('notes')
    ->schema([
        Forms\Components\Textarea::make('contents')
            ->label(fn (Get $get) => User::whereId($get('creator'))->first()->full_name . " - Created at: " . Carbon::parse($get('created_at')) ?? 'Add Note')
            ->maxLength(65535)
            ->required(),
        Forms\Components\Checkbox::make('send_as_email')
            ->hiddenOn('view')
            ->label('Send note as email to client?')
            ->helperText('This sends the contents of the note to the client of this task, as an email.')
            ->default(false),
    ])
    ->mutateRelationshipDataBeforeCreateUsing(function (array $data) {
        $data['creator'] = auth()->id();
        return $data;
    })
    ->columnSpanFull()
    ->defaultItems(0),
Repeater::make('notes')
    ->relationship('notes')
    ->schema([
        Forms\Components\Textarea::make('contents')
            ->label(fn (Get $get) => User::whereId($get('creator'))->first()->full_name . " - Created at: " . Carbon::parse($get('created_at')) ?? 'Add Note')
            ->maxLength(65535)
            ->required(),
        Forms\Components\Checkbox::make('send_as_email')
            ->hiddenOn('view')
            ->label('Send note as email to client?')
            ->helperText('This sends the contents of the note to the client of this task, as an email.')
            ->default(false),
    ])
    ->mutateRelationshipDataBeforeCreateUsing(function (array $data) {
        $data['creator'] = auth()->id();
        return $data;
    })
    ->columnSpanFull()
    ->defaultItems(0),


I want to sort this by created_at so the newest is at the top; Is there a way I can do this?
Solution
Something to try - add the orderBy on the relationship definition:
   return $this->hasMany(Note::class)->orderBy('created_at', 'desc');
   return $this->hasMany(Note::class)->orderBy('created_at', 'desc');
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

table ->defaultSort()
FilamentFFilament / ❓┊help
12mo ago
Defaultsort / column sorting
FilamentFFilament / ❓┊help
3y ago
Issue with ExportAction on table with defaultSort() on a relationship attribute
FilamentFFilament / ❓┊help
2y ago
defaultSort() with an enum
FilamentFFilament / ❓┊help
9mo ago