Download the PHP package aqjw/filterable without Composer
On this page you can find all versions of the php package aqjw/filterable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aqjw/filterable
More information about aqjw/filterable
Files in aqjw/filterable
Package filterable
Short Description The `Filterable` package is designed for Laravel 8.x+ and provides tools for creating and managing filters for Eloquent models. It makes it easy to scale filters and apply them to filter records.
License MIT
Informations about the package filterable
Filterable 📝
The Filterable
package is designed for Laravel 8.x+ and provides tools for creating and managing filters for Eloquent models.
It makes it easy to scale filters and apply them to filter records.
Get Started 🚀
Installation
The package can be easily installed via Composer using the following command:
Adding the HasFilters
Trait
After installation, add the HasFilters
trait to the model that you want to filter:
Usage
Create a filter
To create a new filter, use the Artisan make:filter
command:
You can also specify the column to be filtered:
In addition, you can specify a group for the filter:
The filter will then be created in the following group folder:
\App\Filters\Product\ByCategory::class
Applying Filters
Once you have created your filters, you can apply them to your model:
You can use the or
operator to apply multiple filters:
If you need to group filters, you can wrap them in an array:
Checking Request Parameters with the key
Method
The key
method in the filter class is used to check if a certain key exists in the request parameters. If the key is not present, the filter will not be applied.
Here is an example of how the key
method can be used:
In this example, the ByPrice
filter will only be applied if the price
key is present in the request parameters.
Overriding the isActive
Method
If you want to force a filter to be applied even if the corresponding key is not present in the request parameters, you can override the isActive
method in the filter class.
Here is an example of how the isActive
method can be used:
In this example, the ByCategory
filter will always be applied, even if the category
key is not present in the request parameters. If the category
key is present, the filter will be applied based on its value. If the category
key is not present, the filter will default to showing products in the root category (category ID of 1).
License
The Filterable
package is open-sourced software licensed under the MIT License. Please see the License File for more information.
Contributing
Contributions are welcome! If you would like to contribute to this project, please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/your-feature
) - Make your changes
- Push your branch to your forked repository (
git push origin feature/your-feature
) - Open a pull request