PHPackages                             soliudeen999/laravel-query-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. soliudeen999/laravel-query-filter

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

soliudeen999/laravel-query-filter
=================================

A powerful and flexible query filter system for Laravel applications

00PHP

Since Nov 28Pushed 5mo agoCompare

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

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Laravel Simple Query Filter
===========================

[](#laravel-simple-query-filter)

A powerful and flexible query filter and search system for Laravel applications that allows you to easily filter and search your Eloquent models based on request parameters.

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

[](#installation)

You can install the package via composer:

```
composer require soliudeen999/laravel-query-filter
```

Setup
-----

[](#setup)

Add the `HasFilter` trait to your model and define the filterable fields:

```
use Soliudeen999\QueryFilter\Traits\HasFilter;

class User extends Model
{
    use HasFilter;

    protected array $filterables = [
        'name',
        'email',
        'status',
        'role' => ['admin', 'user', 'guest'],
        'posts' => 'posts:title',
        'withTrashed' => ['with', 'only']
    ];
}
```

Usage
-----

[](#usage)

### Basic Filtering

[](#basic-filtering)

```
// Filter using request parameters automatically
$users = User::filter()->get();

// Filter with specific parameters
$users = User::filter(['status' => 'active'])->get();

// Filter multiple fields
$users = User::filter([
    'status' => 'active',
    'role' => 'admin'
])->get();
```

### Advanced Filtering

[](#advanced-filtering)

#### Comparison Operators

[](#comparison-operators)

The following operators are supported:

- `gt` (greater than)
- `lt` (less than)
- `eq` (equals)
- `neq` (not equals)
- `gte` (greater than or equal)
- `lte` (less than or equal)
- `btw` (between)
- `in` (in array)

```
// Using operators
$users = User::filter([
    'age' => ['gt' => 18, 'lt' => 65],
    'status' => ['in' => ['active', 'pending']],
    'price' => ['btw' => [100, 200]],
    'rating' => ['gte' => 4.5]
])->get();
```

#### Relationship Filtering

[](#relationship-filtering)

Define relationship filters in your `$filterables` array:

```
protected array $filterables = [
    'posts' => 'posts:relationship,title', // format: 'table:relationship,column'
    'comments' => 'comments:relationship,content'
];

// Usage
$users = User::filter([
    'posts' => 'Laravel', // Find users with posts containing 'Laravel' in title
    'comments' => ['active'] // Find users with these comment types
])->get();
```

#### Special Values Filtering

[](#special-values-filtering)

Define allowed values in your `$filterables` array:

```
protected array $filterables = [
    'role' => ['admin', 'user', 'guest'],
    'status' => ['active', 'inactive']
];

// Usage
$users = User::filter([
    'role' => 'admin',  // Will only filter if 'admin' is in allowed values
    'status' => 'active'
])->get();
```

Setup
-----

[](#setup-1)

Add the `HasSearch` trait to your model and define the searchable fields:

```
use Soliudeen999\QueryFilter\Traits\HasFilter;

class User extends Model
{
    use HasSearch;

    protected array $searchable = [
        'name',
        'email',
        'status',
        'posts:name'
    ];
}
```

Usage
-----

[](#usage-1)

### Basic Filtering

[](#basic-filtering-1)

```
// Filter using request parameters automatically
$users = User::search('what to look for')->get();

// Filter with specific parameters
$users = User::search('what to look for')->get();

// Filter multiple fields
$users = User::search('what to look for')->get();
```

### Request Parameters

[](#request-parameters)

When using request parameters, you can filter using query string parameters:

```
/users?name=John&status=active&age[gt]=18&age[lt]=65&sort=-created_at
```

Best Practices
--------------

[](#best-practices)

1. Always define the `$filterables` array in your model to specify which fields can be filtered
2. Use type hints and validation where possible
3. Keep the filter values consistent with your database schema
4. Use relationship filters for complex queries
5. Implement custom search scopes for specific search requirements

Error Handling
--------------

[](#error-handling)

The package will throw exceptions for:

- Missing `$filterables` property
- Invalid relationship filter configurations
- Invalid operator usage
- Invalid between clause values

Make sure to handle these exceptions appropriately in your application.

Testing
-------

[](#testing)

```
composer test
```

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)

- [Soliudeen999](https://github.com/soliudeen999)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance49

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![Soliudeen999](https://avatars.githubusercontent.com/u/50025579?v=4)](https://github.com/Soliudeen999 "Soliudeen999 (3 commits)")

### Embed Badge

![Health badge](/badges/soliudeen999-laravel-query-filter/health.svg)

```
[![Health](https://phpackages.com/badges/soliudeen999-laravel-query-filter/health.svg)](https://phpackages.com/packages/soliudeen999-laravel-query-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)
