New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

javaabu/filters

Filters and sorts for Laravel index pages: define each filter once, apply it to the query from the URL, and render the filter bar, applied-filter chips and sort controls in Blade (javaabu/forms) or Inertia React (@javaabu/forms) through javaabu/stencil.
181
Install
composer require javaabu/filters:v1.0.0-alpha.1
Latest Version:v1.0.0-alpha.1
PHP:^8.4
Laravel:12 · 13
License:MIT
Last Updated:Nov 24, 2026
Links: GitHub  ·  Packagist
Maintainer: dash8x

Filters

Tests codecov Latest Version on Packagist License: MIT

Filters and sorts for Laravel index pages. Define each filter once: how it renders (with javaabu/stencil fields) and how it applies to the query. The filter state lives in the URL, and the filter bar, applied-filter chips and sort controls render in Blade (javaabu/forms) or Inertia React (@javaabu/forms).

class ArticleFilters extends Filters
{
    protected ?string $model = Article::class;

    protected ?string $default_sort = 'published_at';

    protected string $default_direction = 'desc';

    protected function filters(): array
    {
        return [
            TextFilter::make('search')->columns(['title', 'author.name'])->thaana(),
            SelectFilter::make('status')->options(ArticleStatuses::class)->multiple(),
            SelectFilter::make('category_id')->relationship('category', 'name'),
            DateRangeFilter::make('published_at'),
            TrashedFilter::make(),
        ];
    }

    protected function sorts(): array
    {
        return [Sort::make('title'), Sort::make('published_at')->defaultDirection('desc')];
    }
}
$filters = ArticleFilters::make();                                     // reads the query string
$articles = $filters->apply(Article::query())->paginate()->withQueryString();
{{ $filters }}                                                         {{-- the filter bar and chips --}}
<x-filters::heading :filters="$filters" sort="title" />               {{-- a sortable column --}}
<FilterBar filters={filters} />                                        // Inertia::render('Articles/Index', ['filters' => $filters])
<SortableHeading filters={filters} sort="title" />

The URL holds the state in the flat parameters javaabu/forms already uses (?search=ރާއްޖެ&status[]=draft&orderby=title&order=DESC), and values that aren't allowed are ignored.

Documentation

You'll find the documentation on https://docs.javaabu.com/filters, and in the docs folder.

AI coding assistants can start from llms.txt. The package ships a Laravel Boost skill and guideline, which Boost finds by itself. See AI assistants.

Testing

composer test
pnpm test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email info@javaabu.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

javaabu/widgets

WordPress classic-style widgets for Laravel: widget classes with javaabu/stencil...

55 0
javaabu/form-builder

Dynamic forms for Laravel: versioned form definitions and entries in the databas...

33 0
javaabu/stencil

Fluent form schemas for Laravel: define a form once in PHP and render it with Bl...

506 0
javaabu/bulk-actions

Fluent bulk actions for Laravel: each authorized through the Gate with can(), op...

105 0

Version History

Pre-releases (1)
Version Released PHP Laravel License
v1.0.0-alpha.1 ^8.4 ^12.0 || ^13.0 MIT