Florin
Autopopulate SelectFilter by table values?
I ve tried something like this "Filter::make('vehicle_filter')
->form([
Select::make('make_id')
->label('Marca')
->options(fn() => Stock::with('make')
->selectRaw('make_id, COUNT() as count')
->groupBy('make_id')
->get()
->mapWithKeys(fn($item) => [
$item->make_id => optional($item->make)->name . " ({$item->count})"
])
->toArray()
)
->multiple()
->searchable(),
Select::make('model')
->label('Model')
->options(fn(callable $get) =>
Stock::when(filled($get('make_id')), fn($query) =>
$query->whereIn('make_id', $get('make_id'))
)
->selectRaw('model, COUNT() as count')
->groupBy('model')
->get()
->mapWithKeys(fn($item) => [$item->model => "{$item->model} ({$item->count})"])
->toArray()
)
->multiple()
->searchable(),
])
->query(function (Builder $query, array $data): Builder {
return $query
->when(!empty($data['make_id']), fn($query) => $query->whereIn('make_id', $data['make_id']))
->when(!empty($data['model']), fn($query) => $query->whereIn('model', $data['model']));
});" but the query is not being executed
28 replies
Autopopulate SelectFilter by table values?
Yes but is not a relationship, basicly i want to be able to select the second filter dependent on the first one, I have the fallowing "SelectFilter::make('make_id')
->label('Marca')
->options(fn() => Stock::with('make')
->selectRaw('make_id, COUNT() as count')
->groupBy('make_id')
->get()
->mapWithKeys(fn($item) => [$item->make_id => optional($item->make)->name." ({$item->count})"])
->toArray()
)
->multiple()
->searchable(),
SelectFilter::make('model')
->label('Model')
->options(fn() => Stock::selectRaw('model, COUNT() as count')
->groupBy('model')
->get()
->mapWithKeys(fn($item) => [$item->model => "{$item->model} ({$item->count})"])
->toArray()
)
->multiple()
->searchable(),"
28 replies