Table Filter With All Entries From DB Column

Hi, I'm trying to set up a simple SelectFilter with a list of all the distinct values from the 'tag' column (which is a string - more like a typical laravel slug). The filter is:
SelectFilter::make('tag')
SelectFilter::make('tag')
The result is attached - no tags are listed. Any idea what I'm doing wrong?
5 Replies
moaaz_m_f
moaaz_m_f2y ago
I believe you need to use the options
SelectFilter::make('tag')->options(YourModel::all()->pluck('tag', 'tag'))
SelectFilter::make('tag')->options(YourModel::all()->pluck('tag', 'tag'))
and you can add ->multiple() for multi choice
Dan Harrin
Dan Harrin2y ago
YourModel::query()->distinct()->pluck('tag', 'tag') is how to do it with proper performance
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
_andypeacock
_andypeacockOP2y ago
You're all stars! That worked. Thanks so much everyone.
toeknee
toeknee2y ago
And pass it in a closure too, sometimes it can cause multiple excessive queries fn() => Certificate
Want results from more Discord servers?
Add your server