Download the PHP package 7amoood/eloquent-filter without Composer
On this page you can find all versions of the php package 7amoood/eloquent-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-filter
Eloquent Filter
A Laravel package that provides an Eloquent trait for filtering, sorting, searching, and range queries driven entirely by request parameters.
Requirements
- PHP 8.2+
- Laravel 11 or 12
Installation
The service provider is auto-discovered. To publish the config file:
Quick Start
Add the HasFilter trait to your model and define which columns are filterable:
Then call the filter() scope in your controller:
All filtering is now controlled via query string parameters.
Filter Types
Sorting
Sort results by an allowed column.
keymust be listed in the model's$sortColsarray.typeisascordesc(defaults to the value in config).
Search
Search across multiple columns with a single term:
Or search specific fields:
Searchable columns are defined in $filterSearchCols.
Column Filters
Filter by exact column values (comma-separated for multiple):
Passing an empty value filters for NULL:
Allowed columns are defined in $filterCols.
Nested Relationship Filters
Filter through relationships using $filterColsChilds:
Fetch
Fetch specific records by ID (or another column), bypassing any limit:
The $filterFetch property controls allowed columns (defaults to ['id']).
Column Range
Filter by a value range on any column (numeric, string, etc.). Supports providing both from and to, or just one of them:
Allowed columns are defined in $filterRangeColumn.
Date Range
Filter by a date range:
Allowed columns are defined in $filterRangeDate.
Time Range
Filter by a time range (handles overnight spans like 22:00 to 06:00):
Allowed columns are defined in $filterRangeTime.
Limit
Override the per-page count (capped by $filterLimit or the config default):
Model Properties Reference
| Property | Type | Description |
|---|---|---|
$sortCols |
array |
Columns allowed for sorting |
$filterSearchCols |
array |
Columns included in search queries |
$filterCols |
array |
Columns allowed for exact-match filtering |
$filterColsChilds |
array |
Relationship columns for nested filtering |
$filterFetch |
array |
Columns allowed for fetch (default: ['id']) |
$filterRangeColumn |
array |
Columns allowed for generic value range filtering |
$filterRangeDate |
array |
Columns allowed for date range filtering |
$filterRangeTime |
array |
Columns allowed for time range filtering |
$filterLimit |
int |
Max per-page limit for this model |
Column Aliasing
All column arrays support aliasing via key-value pairs. The key is the public name used in the request, and the value is the actual database column:
Configuration
After publishing, the config file is at config/eloquent-filter.php:
Custom Request Key
You can override the request key per-call:
Dynamic Sort Columns
Add sort columns at query time with the sortCols scope:
License
MIT
All versions of eloquent-filter with dependencies
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0