F
Filament6mo ago
ericmp

How to share resource table to relation manager without modifying the query

SongResource: i have a table then, in ArtistResource, i have a SongsRelationManager (artist n n song) so i found out that in the SongsRelationManager i can do this:
public function table(Form $table): Form
{
return SongResource::table($table);
}
public function table(Form $table): Form
{
return SongResource::table($table);
}
but i see all the songs, not the artist's ones. then, to solve it i modified the query:
public function table(Form $table): Form
{
return SongResource::table($table)->query(Song::query()->whereHas('artists', fn ($q) => $q->where('artists.id', $this->ownerRecord->id)));
}
public function table(Form $table): Form
{
return SongResource::table($table)->query(Song::query()->whereHas('artists', fn ($q) => $q->where('artists.id', $this->ownerRecord->id)));
}
so its done. but no! cuz songs have genres. in this case im assuming a song has only 1 genre and 1 genre has many songs. this being said, now i have an issue with the modified query. now i dont know if i have to search for artists relationship or if i have to search in the genre_id field :/ what would u do?
0 Replies
No replies yetBe the first to reply to this messageJoin