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 (playlist_song.order).

I just added a new resource into my PlaylistResource -> 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 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')
            )
        ;
    }
}


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