FilamentF
Filamentβ€’13mo ago
noahlocke

Custom Filter - Multi-Select on Pivot

Struggling to get this filter to work... It only filters on a single value selected, but if I select multiple it's not applying the correct "OR" logic one would expect. This filter is on a table for a NoteResource. Notes belong to a Client, and Clients belong to a Program... the query I'm using worked fine in Laravel Nova for a multi-select filter, so not sure what Filament might be expecting to be different... help! πŸ™‚
Filter::make('program')
  ->form([
      Forms\Components\Select::make('program')
      ->multiple()
      ->options(function(){
          $arr = [];
          $programs = Program::all();
          foreach ($programs as $program) {
              $arr[$program->id] = $program->name;
          }
          return $arr;
      })
  ])
  ->query(function (Builder $query, array $data): Builder {
      return $query->whereHas('client', function($q) use ($data) {
          return $q->where('program_id', $data);
      });
  })
Solution
Woops, need to using whereIn() when passing an array πŸ€¦β€β™‚οΈ
Was this page helpful?