PHPackages                             janakkapadia/filterable - 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. janakkapadia/filterable

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

janakkapadia/filterable
=======================

Enhance your Laravel app with dynamic, customizable filtering for Eloquent models. This package provides an easy setup for multi-parameter filtering, custom logic, and relationship support—perfect for building flexible, data-driven features like admin panels and reports.

0.0.7(1y ago)116MITPHPPHP ^8.1

Since Nov 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/janakkapadia/filterable)[ Packagist](https://packagist.org/packages/janakkapadia/filterable)[ Fund](https://www.buymeacoffee.com/janak.kapadia)[ RSS](/packages/janakkapadia-filterable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

Filterable Package
==================

[](#filterable-package)

A custom Laravel package for dynamic filtering of models, built to simplify the process of filtering data in Laravel applications.

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

[](#installation)

1. **Install via Composer**

    Run the following command to add the package to your Laravel project:

    ```
    composer require janakkapadia/filterable
    ```
2. **Usage**

    This package provides a command to generate filter models dynamically.

    Creating a New Filter Model:

    ```
    php artisan filter:model {ModelName}
    ```
3. **Add Filter Trait to Your Model**

    ```
    use JanakKapadia\Filterable\Traits\Filter;

    class YourModel extends Model
    {
        use Filter;

        // Additional model code...
    }
    ```
4. **Usage In Controller**

    Basic filtering:

    ```
    public function index(Request $request)
    {
        $data = YourModel::filter()->get();
    }
    ```

    With parentheses wrapping where conditions:

    ```
    public function index(Request $request)
    {
        $data = YourModel::filter(true)->get();
    }
    ```
5. **Request Example**

    To filter and sort the data, you can make a request like this:

    ```
    GET URL/your-model?sort_by=id&search=title&status=active

    ```
6. **Example Usage For Model Filter File**

    In your filter model (YourModelFilter.php), you can define both filter and sort methods:

    ```
    class YourModelFilters extends Filter
    {
        // Define your filterable fields
        protected array $filters = ['search', 'status'];

        // Define your sortable fields
        protected array $sort = ['sort_by'];

        // Sort method
        public function sort_by($column): void
        {
            $this->builder->orderBy($column);
        }

        // Filter methods
        public function search($keyword): void
        {
            $this->builder->where(function ($query) use ($keyword) {
                $query->where('field1', 'like', "%$keyword%")
                    ->orWhere('field2', 'like', "%$keyword%");
            });
        }

        public function status($status): void
        {
            $this->builder->where('status', $status);
        }
    }
    ```
7. **Query Examples**

    Without parentheses (`filter()`):

    ```
    SELECT * FROM your_models
    WHERE field1 LIKE '%keyword%'
    OR field2 LIKE '%keyword%'
    AND status = 'active'
    ORDER BY id DESC
    ```

    With parentheses (`filter(true)`):

    ```
    SELECT * FROM your_models
    WHERE (field1 LIKE '%keyword%' OR field2 LIKE '%keyword%')
    AND (status = 'active')
    ORDER BY id DESC
    ```

    The parentheses version ensures proper grouping of conditions and can prevent unexpected results when combining multiple filters.
8. **Advanced Features**

    - **Parentheses Wrapping**: Use `filter(true)` to wrap where conditions in parentheses for complex queries
    - **Filter Chaining**: You can chain multiple filter operations together
    - **Separate Filter and Sort Fields**: Define filterable fields in `$filters` array and sortable fields in `$sort` array

[!["Buy Me A Coffee"](https://camo.githubusercontent.com/9f44ce2dc3b3eecdd02598900866ffc518801df1932849703dae1e5ce5031070/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f637573746f6d5f696d616765732f6f72616e67655f696d672e706e67)](https://buymeacoffee.com/janak.kapadia)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance46

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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 ~28 days

Total

6

Last Release

406d ago

### Community

Maintainers

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

---

Top Contributors

[![janakkapadia](https://avatars.githubusercontent.com/u/46623980?v=4)](https://github.com/janakkapadia "janakkapadia (16 commits)")

### Embed Badge

![Health badge](/badges/janakkapadia-filterable/health.svg)

```
[![Health](https://phpackages.com/badges/janakkapadia-filterable/health.svg)](https://phpackages.com/packages/janakkapadia-filterable)
```

###  Alternatives

[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[swisnl/laravel-fulltext

Fulltext indexing and searching for Laravel

184104.5k5](/packages/swisnl-laravel-fulltext)[romanstruk/manticore-scout-engine

Laravel Manticore Scout Engine

4818.1k](/packages/romanstruk-manticore-scout-engine)[statamic-rad-pack/meilisearch

meilisearch search driver for Statamic

1661.7k](/packages/statamic-rad-pack-meilisearch)[internachi/blade-alpine-instantsearch

Algolia instant search as Blade/Alpine.js components

1940.9k](/packages/internachi-blade-alpine-instantsearch)

PHPackages © 2026

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