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),


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');
Was this page helpful?