PHPackages                             israr22/searchable-select - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. israr22/searchable-select

ActiveLibrary[Search &amp; Filtering](/categories/search)

israr22/searchable-select
=========================

A Laravel Nova Searchable Dependent Select filter.

v1.0.0(1y ago)41.6kMITPHPPHP &gt;=7.1.0

Since Feb 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Israr22/searchable-select)[ Packagist](https://packagist.org/packages/israr22/searchable-select)[ RSS](/packages/israr22-searchable-select/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

Nova Searchable Dependent Filter
--------------------------------

[](#nova-searchable-dependent-filter)

This package provides filters what depends of another filters.

1. [Installation](#user-content-installation)
2. [Usage](#user-content-usage)
    1. [Declaration](#user-content-declaration)
    2. [Class declaration](#user-content-class-declaration)
    3. [Static dependencies](#user-content-static-dependencies)
    4. [Dynamic dependencies](#user-content-dynamic-dependencies)
    5. [Hiding empty filters](#user-content-hiding-empty-filters)
    6. [Default filter value](#user-content-default-filter-value)
    7. [Other stuffs](#user-content-other-stuffs)
3. [Thanks](#user-content-thanks)

Installation
------------

[](#installation)

You can install the package in to a Laravel app that uses [Nova](https://nova.laravel.com) via composer:

```
composer require israr22/searchable-select
```

Usage
-----

[](#usage)

### Declaration

[](#declaration)

You can declare filters in you filters method directly:

```
function filters(Request $request)
{
    return [
        (new SearchableSelect('State'))
            ->withOptions([
                'all' => 'All orders',
                'dragt' => 'Draft',
                'outstanding' => 'Outstanding',
                'past_due' => 'Past due',
                'paid' => 'Paid',
            ]),
    ];
}
```

Also you can use `SearchableSelect::make()` instead `new SearchableSelect()`.

For queries you need to use callback declaration:

```
function filters(Request $request)
{
    return [
        SearchableSelect::make('Category', 'category_id'))
            ->withOptions(function (Request $request) {
                return Category::pluck('title', 'id');
            }),
    ];
}
```

> Note: In difference with Nova filters filter's `value` need pass as array key and `label` as array value.

### Class declaration

[](#class-declaration)

As is Nova filters you can create filter's class:

```
class CategoryFilter extends SearchableSelect
{
    /**
     * Name of filter.
     *
     * @var string
     */
    public $name = 'Category';

    /**
     * Attribute name of filter. Also it is key of filter.
     *
     * @var string
     */
    public $attribute = 'ctaegory_uid';

    public function options(Request $request, array $filters = [])
    {
        return Category::pluck('title', 'id');
    }
}
```

> Note: The `fresh` method is identical with the callback for declaring options.

```
function filters(Request $request)
{
    return [
        CategoryFilter::make(),
    ];
}
```

### Static dependencies

[](#static-dependencies)

For creating dependent filter you need to specify dependent filters values at which the option will be shown:

```
function filters(Request $request)
{
    return [
        CategoryFilter::make(),

        SubCategory::make('Subcategory', 'subcategory_id')
            ->withOptions(function (Request $request) {
                return SubCategory::all()->map(function ($subcategory) {
                    return [
                        'value' => $subcategory->id,
                        'label' => $subcategory->title.
                        'depends' => [
                            'category_id' => $subcategory->category_id, //Also you can set array of values
                        ],
                    ];
                });
            }),
    ];
}
```

> Note. Instead of an attribute or class name, you must specify the key of the filter.

### Dynamic dependencies

[](#dynamic-dependencies)

For big collection of data you can use dynamic updating of the filter.

```
function filters(Request $request)
{
    return [
        StateFilter::make('State', 'state_id'),

        SearchableSelect::make('City', 'city_id')
            ->dependentOf('state_id')
            ->withOptions(function (Request $request, $filters) {
                return City::where('state_id', $filters['state_id'])
                    ->pluck('title', 'id');
            }),
    ];
}
```

In class declaration you also need to set `$dependentOf` property:

```
class CityFilter extends SearchableSelect
{
    public $dependentOf = ['state_id'];

    function options(Request $request, $filters = [])
    {
        return City::where('state_id', $filters['state_id'])
            ->pluck('title', 'id');
    }
}
```

If you want to show options only when main filter is selected you can use `when` for check it:

```
function options(Request $request, $filters = []) {
    return City::when($filters['state_id'], function ($query, $value) {
        $query->where('state_id', $value)
    })->pluck('title', 'id');
}
```

### Hiding empty filters

[](#hiding-empty-filters)

You can hide filters until they have options.

For it you need set `$hideWhenEmpty` or call `hideWhenEmpty()` method:

```
class CityFilter extends SearchableSelect
{
    public $hideWhenEmpty = true;

}
```

```
function filters(Request $request) {
    return [
        StateFilter::make('State', 'state_id'),

        CityFilter::make('City', 'city_id')->hideWhenEmpty(),
    ];
}
```

### Default filter value

[](#default-filter-value)

If you want to set default value you need to call `withDefault` method with value or overload `default` method in class declaration.

```
function filters(Request $request) {
    return [
        StateFilter::make('State', 'code')->withDefault('WA'),
    ];
}
```

```
class StateFilter extends SearchableSelect
{
    public function default()
    {
        return 'WA';
    }
}
```

### Other stuffs

[](#other-stuffs)

By default filter checking by equal filed specified in `$attribute` and filter value. You can overload it like as in Nova filters:

```
class MyFilter extends SearchableSelect
{
    public function apply(Request $request, $query, $value)
    {
        return $query->where('column', '>=', $value);
    }
}
```

When you use declare style you can set pass apply callback to `withApply` method:

```
function filters(Request $request) {
    return [
        StateFilter::make('State', 'code')->withApply(function ($request, $query, $value) {
            return $query->where('code', '=', $value);
        }),
    ];
}
```

Also you can specify another filter key over method `key`.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance40

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

508d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf804204cb05835384955523efd10f5fbb2d790f778d44f23453cf7811cd14f6?d=identicon)[israr22](/maintainers/israr22)

---

Top Contributors

[![Israr22](https://avatars.githubusercontent.com/u/101167360?v=4)](https://github.com/Israr22 "Israr22 (2 commits)")[![prashantmalik-techcompiler](https://avatars.githubusercontent.com/u/49311017?v=4)](https://github.com/prashantmalik-techcompiler "prashantmalik-techcompiler (1 commits)")

---

Tags

laravelsearchableselectnovadependent

### Embed Badge

![Health badge](/badges/israr22-searchable-select/health.svg)

```
[![Health](https://phpackages.com/badges/israr22-searchable-select/health.svg)](https://phpackages.com/packages/israr22-searchable-select)
```

###  Alternatives

[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45902.0k5](/packages/outl1ne-nova-multiselect-filter)[optimistdigital/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45316.3k](/packages/optimistdigital-nova-multiselect-filter)[outl1ne/nova-input-filter

An input filter for Laravel Nova

241.0M](/packages/outl1ne-nova-input-filter)[suenerds/nova-searchable-belongs-to-filter

Searchable Nova filter for belongsTo relationships.

29626.4k](/packages/suenerds-nova-searchable-belongs-to-filter)[awesome-nova/filter-card

A Laravel Nova card.

25128.2k](/packages/awesome-nova-filter-card)[pos-lifestyle/laravel-nova-date-range-filter

A Laravel Nova date range filter.

16181.8k](/packages/pos-lifestyle-laravel-nova-date-range-filter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
