New

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

oscabrera/laravel-query-filters

A Laravel package for advanced query filtering and conditions.
1,378
Install
composer require oscabrera/laravel-query-filters
Latest Version:v1.0.3
PHP:^8.1
Laravel:9 – 12
License:MIT
Last Updated:Dec 27, 2025
Links: GitHub  ·  Packagist
Maintainer: oscabrera

Laravel Query Filters

A Laravel package for advanced query filtering and conditions.

Latest Version on Packagist Total Downloads

VitePress Code Analysis

built with Codeium

laravel-query-filters

Installation

Install the package via Composer:

composer require oscabrera/laravel-query-filters

Configuration (Optional)

You can publish the configuration file to customize the method name used for applying filters. This is optional, but it provides additional flexibility.

Publish the configuration file:

php artisan vendor:publish --provider="Oscabrera\QueryFilters\QueryFiltersServiceProvider" --tag="config"

This will create a config/query-filters.php file in your Laravel application. You can modify this file to change the method name:

return [
    /*
     * The name of the macro that is added to the Eloquent query builder.
     */
    'method_name' => 'applyFilters',
];

Usage

Here's an example of how to use the QueryFilters in a controller:

use Oscabrera\QueryFilters\Utilities\QueryFilters;
use App\Models\User;
use Illuminate\Http\Request;

public function index(Request $request)
{
    $conditions = [
        'name' => 'John',
        'age' => ['age', '>', 25],
        'status' => ['active', 'pending'],
        'role' => [
            'subQuery' => function($query) {
                return $query->select('id') ->from('roles') ->where('name', 'admin');
            },
            'not' => false,
        ]
    ];
    $queryFilters = new QueryFilters($conditions);
    $users = User::query()->applyFilters($queryFilters)->get();

    return response()->json($users);
}

Features

  • Simple Conditions: Apply simple equality conditions.
  • Array Conditions: Use whereIn conditions for columns.
  • Triple Conditions: Apply conditions with specific operators.
  • SubQueries: Use subqueries for complex filtering.
  • Customizable Method Name: Change the method name for applying filters via configuration.

More Information

For more information, visit the documentation.

By following these instructions, you can easily integrate advanced query filtering into your Laravel applications, customize the filtering method name, and keep your code clean and maintainable.

Related Packages

jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integratio...

52,676 194
exeko/laravel-simple-query-filter

A simple Trait to include in your models to enable filters

7,246 0
lerouse/laravel-repository

Repository implementation for Laravel.

19,760 5
kalimeromk/filterable

A Laravel package that simplifies dynamic filtering and searching across models...

3,114 5
msantang/query-filters

Laravel 4|5 Query Filters with validation and relationship support

40 1

Version History

Version Released PHP Laravel License
v1.0.3 ^8.1 ^9.0|^10.0|^11.0|^12.0 MIT
v1.0.2 ^8.1 ^9.0|^10.0|^11.0 MIT
v1.0.1 ^8.1 ^9.0|^10.0|^11.0 MIT
v1.0.0 ^8.1 ^9.0|^10.0|^11.0 MIT
Pre-releases (2)
Version Released PHP Laravel License
v1.0.0-alpha.2 ^8.1 ^9.0|^10.0|^11.0 MIT
v1.0.0-alpha.1 ^8.1 ^9.0|^10.0|^11.0 MIT