PHPackages                             amitavroy/laravel-sort-and-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. amitavroy/laravel-sort-and-filter

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

amitavroy/laravel-sort-and-filter
=================================

1.0.2(2y ago)69863[1 issues](https://github.com/amitavroy/laravel-sort-and-filter/issues)MITPHPPHP ^7.2 || ^8.3CI failing

Since Jun 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/amitavroy/laravel-sort-and-filter)[ Packagist](https://packagist.org/packages/amitavroy/laravel-sort-and-filter)[ Docs](https://github.com/amitavroy/laravel-sort-and-filter)[ RSS](/packages/amitavroy-laravel-sort-and-filter/feed)WikiDiscussions master Synced 2d ago

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

Laravel Sort and Filter
=======================

[](#laravel-sort-and-filter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/96b58c591fc9b4196e9a3fee70d44396264bb70413ce578ffe36b623061b1aa8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d69746176726f792f6c61726176656c2d736f72742d616e642d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amitavroy/laravel-sort-and-filter)[![Tests](https://github.com/amitavroy/laravel-sort-and-filter/workflows/Tests/badge.svg)](https://github.com/amitavroy/laravel-sort-and-filter/workflows/Tests/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/c6200c36003890b9631df84d032a6585165fe24e9793220a7c524aac7e30f6c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d69746176726f792f6c61726176656c2d736f72742d616e642d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amitavroy/laravel-sort-and-filter)

This package allows you to sort, filter and even search Eloquent models using the Request object.

No need to write conditional code inside you controller to handle sort, filter or search parameters coming from front end through URL (for example from a Javascrpt application)

Just pass the request object and the sorting and filters should automatically work.

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

[](#installation)

You can install the package via composer:

```
composer require amitavroy/laravel-sort-and-filter
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Amitav\SortAndFilter\SortAndFilterServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

This pacakge provides with a Trait which you need to use in any Model that you want to have the ability to sort, filter or search. For example, in the user model, you need to add

```
use SortAndFilter;

```

Once done, you can add the sort, filter or search function to the Model inside a query and pass the request object directly as show below.

You can sort and/or filter on any model after adding the trait as shown below:

```
User::query()
    ->sort($request)
    ->filter($request)
    ->get();
```

With this, you have the ability to pass paramters through URL like this:

```
http://localhost:8000?sortBy=name&sortOrder=desc
http://localhost:8000?filterBy=name&filterValue=Amitav

```

If you want to control which fields can be filtered and which fields can be sorted, then you can create a protected field in your model with name **$sortable** to control sort fields. And, create a protected field with name **$filterable** to control which fields can be used to filter.

You can even search on any model as shown below:

```
User::query()
    ->search($request)
    ->get();
```

NOTE: The search is going to be a database query and the package runs a like query. And hence, be careful about the number of string that you allow in validation before you send the request object for search. Internally, the query will be something like:

```
SELECT * FROM user WHERE name LIKE "amit%";
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Amitav Roy](https://github.com/amitavroy)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 60.4% 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 ~649 days

Total

3

Last Release

863d ago

PHP version history (3 changes)1.0.0PHP ^7.3

1.0.1PHP ^7.2

1.0.2PHP ^7.2 || ^8.3

### Community

Maintainers

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

---

Top Contributors

[![matheusdelima](https://avatars.githubusercontent.com/u/5695569?v=4)](https://github.com/matheusdelima "matheusdelima (29 commits)")[![amitavroy](https://avatars.githubusercontent.com/u/1438890?v=4)](https://github.com/amitavroy "amitavroy (19 commits)")

---

Tags

laravellaravel-packagephpamitavroylaravel-sort-and-filter

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/amitavroy-laravel-sort-and-filter/health.svg)

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

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

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)[handcraftedinthealps/zendsearch

a general purpose text search engine written entirely in PHP 5

39921.0k35](/packages/handcraftedinthealps-zendsearch)

PHPackages © 2026

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