© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
Marcellin

How to Make Multiple Select Filters Combine with 'And' Logic Instead of 'Or' Logic in FilamentPHP?

When I select multiple options from a single Select Filter, it treats them as an orWhere, which is expected. However, when I select options simultaneously from two or more Select Filters, it also treats them as orWhere. However, I need them to be treated as andWhere. How can I achieve this behavior?

Here are two examples of the filters:
SelectFilter::make('type_id')
    ->label('Type')
    ->query(function (Builder $query, array $data): Builder {
        $values = $data['values'];
        foreach ($values as $value) {
            $query = $query->orWhere('types.type_id', $value);
        }
        return $query;
    })
    ->options(Type::all()->pluck('type_name', 'type_id'))
    ->multiple(),
SelectFilter::make('category_id')
    ->label('Category')
    ->query(function (Builder $query, array $data): Builder {
        $values = $data['values'];

        foreach ($values as $value) {
            $query->orWhere('categories.category_id', $value);
        }

        return $query;
    })
    ->options(Category::all()->pluck('category_name', 'category_id'))
    ->multiple();
SelectFilter::make('type_id')
    ->label('Type')
    ->query(function (Builder $query, array $data): Builder {
        $values = $data['values'];
        foreach ($values as $value) {
            $query = $query->orWhere('types.type_id', $value);
        }
        return $query;
    })
    ->options(Type::all()->pluck('type_name', 'type_id'))
    ->multiple(),
SelectFilter::make('category_id')
    ->label('Category')
    ->query(function (Builder $query, array $data): Builder {
        $values = $data['values'];

        foreach ($values as $value) {
            $query->orWhere('categories.category_id', $value);
        }

        return $query;
    })
    ->options(Category::all()->pluck('category_name', 'category_id'))
    ->multiple();
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to Make Multiple Select Filters Combine with 'And' Logic Instead of 'Or' Logic?
FilamentFFilament / ❓┊help
3y ago
How to make a rule "in" of a multiple select
FilamentFFilament / ❓┊help
2y ago
How to make FilamentPHP faster
FilamentFFilament / ❓┊help
3y ago
FilamentPHP at '/' instead of '/admin' ?
FilamentFFilament / ❓┊help
3y ago