Download the PHP package ekramhossain/laravel-query-filter without Composer
On this page you can find all versions of the php package ekramhossain/laravel-query-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ekramhossain/laravel-query-filter
More information about ekramhossain/laravel-query-filter
Files in ekramhossain/laravel-query-filter
Package laravel-query-filter
Short Description A flexible query filtering package for Laravel with operators, date ranges, relational filters, and sorting.
License MIT
Informations about the package laravel-query-filter
Laravel Query Filter
A flexible and lightweight query filtering package for Laravel Eloquent with support for:
- Allowed filters
- String search
- Comparison operators
- Date range filtering
- Relational filtering
- Multiple sorting
- Ascending and descending sorting
Requirements
- PHP
^8.1 - Laravel
9.x - Laravel
10.x - Laravel
11.x - Laravel
12.x
Installation
Install the package via Composer:
The package automatically registers its service provider and Filter facade.
Configuration
Publish the configuration file:
This will publish:
Basic Usage
Suppose you have a Product model:
Basic Filtering
Request:
Equivalent query:
String Filtering
String values are automatically treated as a LIKE search.
Request:
Equivalent query:
Comparison Operators
The following operators are supported:
| Operator | Meaning |
|---|---|
eq |
Equal |
gt |
Greater than |
gte |
Greater than or equal |
lt |
Less than |
lte |
Less than or equal |
Equal
Greater Than
Greater Than Or Equal
Less Than
Less Than Or Equal
Date Range Filtering
Date range filtering is supported using from and to.
Example:
This produces a query equivalent to:
You can use the same syntax with any allowed date column:
Relational Filtering
You can filter records through Eloquent relationships using dot notation.
Example:
Request:
This will use Eloquent's whereHas() internally.
For example:
Nested relationships are also supported:
Sorting
Define allowed sorting columns:
Ascending
Equivalent to:
Descending
Prefix the column with -:
Equivalent to:
Multiple Sorting
Multiple sorting columns can be passed using commas:
Equivalent to:
Multiple Filters
Multiple filters can be combined:
Security
Only fields explicitly defined through allowedFilters() can be filtered.
Only fields defined through allowedSorts() can be sorted.
Unknown filters and sorting fields are ignored.
This prevents users from arbitrarily controlling which database columns are queried.
Complete Example
Example request:
Supported Features
| Feature | Supported |
|---|---|
| Basic filtering | ✅ |
| String LIKE search | ✅ |
eq |
✅ |
gt |
✅ |
gte |
✅ |
lt |
✅ |
lte |
✅ |
| Date range | ✅ |
| Relationship filtering | ✅ |
| Nested relationship filtering | ✅ |
| Ascending sorting | ✅ |
| Descending sorting | ✅ |
| Multiple sorting | ✅ |
| Allowed filters | ✅ |
| Allowed sorts | ✅ |
License
This package is open-sourced software licensed under the MIT License.
Author
Md. Ekram Hossain
GitHub: https://github.com/ekrambd/
All versions of laravel-query-filter with dependencies
illuminate/database Version ^9.0|^10.0|^11.0|^12.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0