oscabrera/laravel-query-filters

A Laravel package for advanced query filtering and conditions.
1,206
Install
composer require oscabrera/laravel-query-filters
Latest Version:v1.0.3
PHP:^8.1
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

tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

5,394,523 1,765
ablunier/laravel-database

Laravel database utilities package. Repository, cache, abstraction layer.

4,453 1
czim/laravel-repository

Repository for Laravel (inspired by and indebted to Bosnadev/Repositories)

115,206 52
czim/laravel-filter

Filter for Laravel Eloquent queries, with support for modular filter building

76,992 89