F
Filamentβ€’12mo ago
ericmp

How to put a link for each badge in TextColumn?

I would like to enable the ability to click on each playlist in the column and open its corresponding link. Below is the current PHP code snippet for creating the column:
TextColumn::make('playlists.name')
->badge()
->label(__('Playlists'))
// ->getStateUsing(function (Song $record) {
// dd($record);
// })
// ->url()
,
TextColumn::make('playlists.name')
->badge()
->label(__('Playlists'))
// ->getStateUsing(function (Song $record) {
// dd($record);
// })
// ->url()
,
How can I modify this code to achieve the desired functionality of clicking on each playlist to open its link?
8 Replies
ericmp
ericmpOPβ€’12mo ago
is possible?
KA
KAβ€’12mo ago
possible, please read the doc. πŸ™‚
ericmp
ericmpOPβ€’12mo ago
what section, badges? (,:
KA
KAβ€’12mo ago
what you wants to do? yes, you can make badge as list and also you can add url.
TextColumn::make('playlists.name')->badge()->listWithLineBreaks()
TextColumn::make('playlists.name')->badge()->listWithLineBreaks()
ericmp
ericmpOPβ€’12mo ago
how using ->listWithLineBreaks would solve my question? how using debounce would solve my question? for each badge, i want to make it clickable like an <a href> tag so i can easily go to the playlist i want by clicking the badge do i explain myself?
ericmp
ericmpOPβ€’12mo ago
its fine, now i have it like this, it works, but seems can be improved:
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'))
,
edit: i moved it into a new question - https://discord.com/channels/883083792112300104/1189548034476998726/1189548034476998726
Want results from more Discord servers?
Add your server