F
Filament6mo ago
ericmp

How to refactor this TextColumn badge link?

TextColumn::make('playlists.name')
->badge()
->url(function (Song $record, $state): string {
$playlist = Playlist::query()->where('name', $state[0])->first();

return route('playlists.edit', $playlist);
})
->label(__('Playlists'))
,
TextColumn::make('playlists.name')
->badge()
->url(function (Song $record, $state): string {
$playlist = Playlist::query()->where('name', $state[0])->first();

return route('playlists.edit', $playlist);
})
->label(__('Playlists'))
,
3 Replies
ericmp
ericmp6mo ago
i would like to get the playlist by it's id instead of name, cuz might be 2 playlists with same name :/ but idk how to do it well, just find out that this doesnt work if the song actually has more than 1 playlist, the link will be always point to the first playlist any ideas on how to achieve it? if u need more context let me know or -> https://discord.com/channels/883083792112300104/1188799442686586890 any ideas?
DrByte
DrByte6mo ago
I'm presuming that 'playlists.name' is referring to the name property on a relationship named playlists. So, wouldn't playlists.id refer to the id of the playlist? Therefore you could refer to (ie: query) the record that way.
ericmp
ericmp6mo ago
thanks hmm ill give it a try
Want results from more Discord servers?
Add your server
More Posts