© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
5 replies
Eric

Reorder table records from a pivot relationship

A playlist belongs to many songs.
A song belongs to many playlists.

The pivot between them has an attribute called
order
order
(
playlist_song.order
playlist_song.order
).

I just added a new resource into my
PlaylistResource
PlaylistResource
->
SongsRelationManager
SongsRelationManager


I want the user to be able to see the songs that a playlist has. also, i want them to be able to change the
playlist_song.order
playlist_song.order
field

This is what i tried:
class SongsRelationManager extends RelationManager
{
    protected static string $relationship = 'songs';

    public function form(Form $form): Form
    {
        return SongResource::form($form);
    }

    public function table(Table $table): Table
    {
        return SongResource::table($table)
            ->reorderable('order')
            ->query(
                Song::query()
                    ->whereHas('playlists', function ($q) {
                        $q->where("playlists.id", $this->ownerRecord->id);
                    })
                    ->orderBy('order')
            )
        ;
    }
}
class SongsRelationManager extends RelationManager
{
    protected static string $relationship = 'songs';

    public function form(Form $form): Form
    {
        return SongResource::form($form);
    }

    public function table(Table $table): Table
    {
        return SongResource::table($table)
            ->reorderable('order')
            ->query(
                Song::query()
                    ->whereHas('playlists', function ($q) {
                        $q->where("playlists.id", $this->ownerRecord->id);
                    })
                    ->orderBy('order')
            )
        ;
    }
}


This is what im getting just loading the view, without even interacting with it:

I expected to be able to change the order successfully
image.png
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Pivot Column Reorder
FilamentFFilament / ❓┊help
3y ago
Create a relationship manager for a pivot table
FilamentFFilament / ❓┊help
3y ago
HasMany Table Relationship pivot/group RelationManager
FilamentFFilament / ❓┊help
2y ago
How to reorder columns by a column in a pivot table
FilamentFFilament / ❓┊help
3y ago