Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vcav's avatar
Level 2

Issue with Filament Form Repeater not reordering items for relationship

I am using Filament form repeaters to integrate with a Has Many relationship, which is described in the docs here. You're supposed to be able to reorder the relationships if you include a sort column, but my sort order is not saving when I drag and drop the repeater item and click save. I CAN change the TextInput inside the schema though. Has anyone else had this same issue or can they help?

My Repeater code:

Forms\Components\Repeater::make('periodical_articles')
                    ->relationship()
                    ->reorderable()
                    ->schema([
                        TextInput::make('title')
                            ->required()
                            ->maxLength(255),
                        TextInput::make('author')
                            ->required()
                            ->maxLength(255),
                        Select::make('type')
                            ->options([
                                'article' => 'Article',
                                'book_review' => 'Book Review',
                            ])
                    ])
                    ->orderColumn('sort')
                    ->columnSpan(3)

The relationship is defined in Periodical:

public function periodical_articles(): HasMany
    {
        return $this->hasMany(PeriodicalArticle::class);
    }

... and in PeriodicalArticle:

public function periodical(): BelongsTo
    {
        return $this->belongsTo(Periodical::class);
    }
0 likes
2 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

It seems like you've set up the repeater correctly according to the Filament documentation. However, if the sort order is not saving, there are a few things you should check:

  1. Ensure that the sort column exists in your periodical_articles table and that it is of a type that can store an integer value (e.g., INTEGER).

  2. Make sure that you are not overriding the save method in your Filament resource or doing anything that could interfere with the saving process of the repeater items.

  3. Verify that the sort column is fillable in your PeriodicalArticle model. You should have something like this in your model:

class PeriodicalArticle extends Model
{
    protected $fillable = ['title', 'author', 'type', 'sort'];
    // ...
}
  1. If you have any custom logic in the saving or saved model events (in your PeriodicalArticle model), ensure that it does not interfere with the sorting.

  2. Check if there are any JavaScript errors in your browser's console when you try to reorder the items. JavaScript errors could prevent the new order from being submitted correctly.

  3. Ensure that you are using the latest version of Filament, as there might have been bug fixes related to the repeater functionality.

If everything seems to be in order and you're still facing issues, you might want to debug by listening to the saving event on the PeriodicalArticle model to see if the sort values are being set correctly:

PeriodicalArticle::saving(function ($periodicalArticle) {
    \Log::info('Saving periodical article with sort order: ' . $periodicalArticle->sort);
});

This will log the sort order every time a PeriodicalArticle is saved. You can check your log files to see if the sort order is being captured correctly.

If you've gone through all these steps and the issue persists, it might be a good idea to reach out to the Filament community or check the GitHub issues for the project to see if anyone else has reported a similar problem or if there's an ongoing bug that needs to be addressed.

1 like
vcav's avatar
Level 2

Lary Quickdraw got it right on suggestion #3. I also found the same thing on Discord.

Please or to participate in this conversation.