PHPackages                             deployfy/nova-dependent-filter - 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. [Admin Panels](/categories/admin)
4. /
5. deployfy/nova-dependent-filter

ActiveLibrary[Admin Panels](/categories/admin)

deployfy/nova-dependent-filter
==============================

A Laravel Nova filter.

1.0.1(5mo ago)13.1k↓29.8%2MITVuePHP ^8.1

Since Jul 12Pushed 5mo agoCompare

[ Source](https://github.com/deployfy/nova-dependent-filter)[ Packagist](https://packagist.org/packages/deployfy/nova-dependent-filter)[ RSS](/packages/deployfy-nova-dependent-filter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

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

[](#nova-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 deployfy/nova-dependent-filter
```

Usage
-----

[](#usage)

### Declaration

[](#declaration)

You can declare filters in you filters method directly:

```
use Deployfy\NovaDependentFilter\SelectDependsFilter;

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

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

For queries you need to use callback declaration:

```
use Deployfy\NovaDependentFilter\SelectDependsFilter;

function filters(Request $request)
{
    return [
        SelectDependsFilter::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:

```
use Deployfy\NovaDependentFilter\SelectDependsFilter;

class CategoryFilter extends SelectDependsFilter
{
    /**
     * 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.

```
use Deployfy\NovaDependentFilter\SelectDependsFilter;
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:

```
use Deployfy\NovaDependentFilter\SelectDependsFilter;
class CityFilter extends SelectDependsFilter
{
    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

40

—

FairBetter than 88% of packages

Maintenance70

Regular maintenance activity

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~137 days

Total

2

Last Release

172d ago

### Community

Maintainers

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

---

Top Contributors

[![diego-drese](https://avatars.githubusercontent.com/u/7375455?v=4)](https://github.com/diego-drese "diego-drese (3 commits)")

---

Tags

laravelnova

### Embed Badge

![Health badge](/badges/deployfy-nova-dependent-filter/health.svg)

```
[![Health](https://phpackages.com/badges/deployfy-nova-dependent-filter/health.svg)](https://phpackages.com/packages/deployfy-nova-dependent-filter)
```

###  Alternatives

[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)[pdmfc/nova-action-button

A Laravel Nova field to run actions.

37733.0k1](/packages/pdmfc-nova-action-button)[khalin/nova-link-field

A Laravel Nova Link field.

31562.2k2](/packages/khalin-nova-link-field)[a2insights/filament-saas

Filament Saas for A2Insights

161.1k](/packages/a2insights-filament-saas)

PHPackages © 2026

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