Download the PHP package buibr/eloquent-filter without Composer
On this page you can find all versions of the php package buibr/eloquent-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download buibr/eloquent-filter
More information about buibr/eloquent-filter
Files in buibr/eloquent-filter
Package eloquent-filter
Short Description Search by filtering query string to eloquent query
License
Informations about the package eloquent-filter
Eloquent Filter
eloquent-filter
is a simple package for filtering Eloquent queries based on request query parameters with predefined methods per parameter. It allows you to easily build complex query filters for your Laravel applications.
Installation
You can install the package via composer:
Usage
Step 1: Add HasFilters
Trait to Your Model
Include the HasFilters
trait in any Eloquent model where you want to use query filters.
Step 2: Create a Filter Class
Create a new filter class that extends QueryFilter
. In this class, define methods for each query parameter you want to filter by. Each method should accept the parameter value and modify the query accordingly.
Step 3: Apply the Filter in Your Controller
In your controller, apply the filter to the query by using the filter
scope. Pass an instance of your filter class as the argument.
Example Request
You can now filter the query by passing parameters in the request URL:
This will apply the status
and category
filters based on the methods defined in your YourModelFilter
class.
Customizing Filters
To customize how filters are applied, simply add more methods to your filter class. Each method corresponds to a query parameter and can modify the Eloquent query as needed.
Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.
License
This package is open-sourced software licensed under the MIT license.