How to render the filter options from database table in Table Builder filter options

srinivas214 - 1 month ago

Hi, I have table with cities (id, city name) and would like to render the cities in the below mentioned filter options by querying from the database instead of the static options. Please help me to fix this

'city' => [ 'filter' => 'select', 'options' => [ 'live' => 'Live', 'draft' => 'Draft', 'scheduled' => 'Scheduled', ], ],

ryanthompson - 1 month ago

For the custom select FT you should just be able to make your options parameter a handler:

'options' => MyOptions::class . '@handle',

'options' => MyOptions::class . '@handle', will be available for method/class injection there:

public function handle(FilterInterface $filter, SomeRepositoryInterface $widgets) {
    return $widgets->all()->pluck('id', 'name');
}

^ Is close to a valid example I think lol