PHPackages                             musta20/laravel-records-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. [Search &amp; Filtering](/categories/search)
4. /
5. musta20/laravel-records-filter

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

musta20/laravel-records-filter
==============================

a laravel packge to filter record

1.0.3(1y ago)016MITBlade

Since Jun 8Pushed 1y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Laravel Records Filter
======================

[](#laravel-records-filter)

Laravel record filter provides an easy and intuitive way to filter and sort records in your Laravel applications. It mimics the familiar syntax of the Laravel Paginator, making it simple to implement complex filtering logic.

Requerment
----------

[](#requerment)

This package requires your app to include tailwind and alpinejs in your views

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

[](#installation)

You can install the package via composer:

```
composer require musta20/laravel-records-filter
```

make sure to rebuild tailwind assets if you are not running vite dev

```
yarn vite build
```

Using the package
-----------------

[](#using-the-package)

In your model use the trait HasFilter:

```
use Musta20\LaravelRecordsFilter\HasFilter;

class Post extends Model
{
    use HasFactory, HasFilter;
```

#### implement the following function in your model according to your need

[](#implement-the-following-function-in-your-model-according-to-your-need)

### Sorting

[](#sorting)

The following example show how to implement sorting

```
    public function sortFilterOptions()
    {

        return  [
            [
                "lable" => "oldest",    // label name to display in the filtering form
                "type" => 'ASC',        // sorting type
                "filed" => "created_at" // talbel filed name
            ],
            [
                "lable" => "newest",
                "type" => 'DESC',
                "filed" => "created_at"
            ],
            [
                "lable" => "high price",
                "type" => 'DESC',
                "filed" => "price"
            ],
            [
                "lable" => " lowest price",
                "type" => 'ASC',
                "filed" => "price"
            ],

        ];
    }

```

### Filter by relation

[](#filter-by-relation)

You can filter record based on relation to other table:

```
    public function relationsFilterOptions()
    {
        return [
            [
                'label' => 'auther',     // label name to display in the filtering form
                'label_filed' => 'name', // filed name in the relation tabel
                'id' => 'user_id',      // label name in the relation tabel
                'model' => 'App\Models\User',
            ],
            [
                'label' => 'category',
                'label_filed' => 'name',
                'id' => 'category_id',
                'model' => 'App\Models\category',
            ]
        ];
    }

```

### Search

[](#search)

You can search in records by defining the table name in search function:

```
    public function searchFields()
    {
        return  [
            'title',
            'body'
        ];
    }
```

### Filtering

[](#filtering)

You can define filtering term like the following :

```
    public function filterOptions()
    {

        return [
            [
                'label' => 'reviewing',     // label name to display in the filtering form
                'type' => 'checkbox',       // checkbox | select | radio group | date | between
                'filed' => 'article_type',  // filed name in the tabel
                'operation' => '=',         // opertaion type
                'options' => [              // the  values you want to filter based on
                    'reviewed' => 1,        // the first key will be used as label
                    'not reviewed' => 0
                ],
            ],
            [
                'label' => 'publish status',
                'type' => 'select',    //checkbox | select | radio group | date | between
                'filed' => 'is_published',
                'options' => [
                    'drafted' => 0,
                    'publish' => 1
                ]

            ],
            [
                'label' => 'font size',
                'type' => 'radio group', //checkbox | select | radio group | date | between
                'filed' => 'font_type',
                'options' => [
                    'small' => 10,
                    'big' => 20
                ]

            ],
            [
                'label' => 'issue date',
                'type' => 'date', //checkbox | select | radio group | date | between
                'filed' => 'created_at',
                'operation' => '='

            ]
            ,
            [
                'label' => 'issue period',
                'type' => 'range', //checkbox | select | radio group | date | between
                'filed' => 'created_at',
                'inputType' => 'date',//date/number
                'operation' => 'between',
                'options' => [
                    'from',
                    'to'
                ]
            ]
            ,
            [
                'label' => 'price range',
                'type' => 'range', //checkbox | select | radio group | date | between
                'filed' => 'price',
                'inputType' => 'number',//date/number
                'operation' => 'between',
                'options' => [
                    'max',
                    'min'
                ]
            ]
        ];
    }

```

### querying

[](#querying)

you must use the function Filter() to retrieve the data keep in mind you have to call it the last in the query and do not call the paginate as it automatically paginated

```
    $posts= Post::filter();

    // or

    $posts=  Post::where('name','alie')->filter();
```

Finally, run in your view call the filter nav using the function.

```
{{ $posts->filterLinks() }}
```

[![Screenshot from 2024-06-10 13-01-00](https://private-user-images.githubusercontent.com/46521416/338147787-d702564d-1550-472c-adef-a289e2527372.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUyMDcyMTgsIm5iZiI6MTc3NTIwNjkxOCwicGF0aCI6Ii80NjUyMTQxNi8zMzgxNDc3ODctZDcwMjU2NGQtMTU1MC00NzJjLWFkZWYtYTI4OWUyNTI3MzcyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAzVDA5MDE1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTkzZGIxNjI0MGM2MWUzOTRiMzMxMDRjZjQ5YTFkODExMDExMjVkNWQ3ZGNkMzQ5YWY5OGU5YWQ0ZDQ1ZDRmNzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.kN_6gO4Hf7duWfdtldqsRGpfgPRuqubXd5KQd7khh8U)](https://private-user-images.githubusercontent.com/46521416/338147787-d702564d-1550-472c-adef-a289e2527372.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUyMDcyMTgsIm5iZiI6MTc3NTIwNjkxOCwicGF0aCI6Ii80NjUyMTQxNi8zMzgxNDc3ODctZDcwMjU2NGQtMTU1MC00NzJjLWFkZWYtYTI4OWUyNTI3MzcyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAzVDA5MDE1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTkzZGIxNjI0MGM2MWUzOTRiMzMxMDRjZjQ5YTFkODExMDExMjVkNWQ3ZGNkMzQ5YWY5OGU5YWQ0ZDQ1ZDRmNzYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.kN_6gO4Hf7duWfdtldqsRGpfgPRuqubXd5KQd7khh8U)

You can use different view like nav-filter to show all filtering option in linear view

```
 {{ $posts->filterLinks('laravelRecordsFilter::nav-filter') }}
```

[![Screenshot from 2024-06-10 13-46-03](https://private-user-images.githubusercontent.com/46521416/338152970-eb1668e6-acbc-48fb-b5db-4aaf39799028.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUyMDcyMTgsIm5iZiI6MTc3NTIwNjkxOCwicGF0aCI6Ii80NjUyMTQxNi8zMzgxNTI5NzAtZWIxNjY4ZTYtYWNiYy00OGZiLWI1ZGItNGFhZjM5Nzk5MDI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAzVDA5MDE1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcxZjgyY2U2OTkyNzgzZmI3NDUxMGY2MDY1ZmQ1ZWIyYTUyYTVhYjdmMDk3MWYwNTNiNmFmNGE4ODUzMjI4MjQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.v8KA4m0UPoObXuCBmCC1K2esc-_d0vIj4bR8T9Scrbw)](https://private-user-images.githubusercontent.com/46521416/338152970-eb1668e6-acbc-48fb-b5db-4aaf39799028.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUyMDcyMTgsIm5iZiI6MTc3NTIwNjkxOCwicGF0aCI6Ii80NjUyMTQxNi8zMzgxNTI5NzAtZWIxNjY4ZTYtYWNiYy00OGZiLWI1ZGItNGFhZjM5Nzk5MDI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAzVDA5MDE1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTcxZjgyY2U2OTkyNzgzZmI3NDUxMGY2MDY1ZmQ1ZWIyYTUyYTVhYjdmMDk3MWYwNTNiNmFmNGE4ODUzMjI4MjQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.v8KA4m0UPoObXuCBmCC1K2esc-_d0vIj4bR8T9Scrbw)

You can also display filtering option in sidebar view by using the following function

for the side bar :

```
  {{ $posts->filterLinks('laravelRecordsFilter::sidebar-filter') }}
```

for the nav :

```
   {{ $posts->filterNav() }}
```

[![Screenshot from 2024-06-10 13-55-58](https://private-user-images.githubusercontent.com/46521416/338156069-9fe2cfbc-7749-4ceb-9d31-85d66ab12ff8.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUyMDcyMTgsIm5iZiI6MTc3NTIwNjkxOCwicGF0aCI6Ii80NjUyMTQxNi8zMzgxNTYwNjktOWZlMmNmYmMtNzc0OS00Y2ViLTlkMzEtODVkNjZhYjEyZmY4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAzVDA5MDE1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYyYzU3OWJlNGFlMzk3YmEyZGZmOWMzMGVmYzFkMjMyNWMxMWQ5MDZjZWRkNjI1YWFlNDAyZWU2ODIzMjhhYzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.grzuLn5DmxTfakbnctsv-ivIKPcNquwbiOO1xIzykrM)](https://private-user-images.githubusercontent.com/46521416/338156069-9fe2cfbc-7749-4ceb-9d31-85d66ab12ff8.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzUyMDcyMTgsIm5iZiI6MTc3NTIwNjkxOCwicGF0aCI6Ii80NjUyMTQxNi8zMzgxNTYwNjktOWZlMmNmYmMtNzc0OS00Y2ViLTlkMzEtODVkNjZhYjEyZmY4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDAzVDA5MDE1OFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYyYzU3OWJlNGFlMzk3YmEyZGZmOWMzMGVmYzFkMjMyNWMxMWQ5MDZjZWRkNjI1YWFlNDAyZWU2ODIzMjhhYzQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.grzuLn5DmxTfakbnctsv-ivIKPcNquwbiOO1xIzykrM)

now of curse the view will not always match your style so you can publish the view and edit it the way you want

```
php artisan vendor:publish --tag=laravel-Records-Filter
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.txt) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Total

4

Last Release

627d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/08d250ce00da654ceb60ddbb122f1a13e3186c49ac8f3cdd135967a1a3277ced?d=identicon)[musta20](/maintainers/musta20)

---

Top Contributors

[![musta20](https://avatars.githubusercontent.com/u/46521416?v=4)](https://github.com/musta20 "musta20 (49 commits)")

### Embed Badge

![Health badge](/badges/musta20-laravel-records-filter/health.svg)

```
[![Health](https://phpackages.com/badges/musta20-laravel-records-filter/health.svg)](https://phpackages.com/packages/musta20-laravel-records-filter)
```

###  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.5k6](/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)
