Download the PHP package kayckmatias/z-filters without Composer
On this page you can find all versions of the php package kayckmatias/z-filters. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kayckmatias/z-filters
More information about kayckmatias/z-filters
Files in kayckmatias/z-filters
Package z-filters
Short Description a simple way to dynamically filter your Laravel models
License MIT
Informations about the package z-filters
zFilters
a simple package to filter your Laravel models without repetitive loops or various if-else
Installation
You can install the package via composer:
Usage
You just need two things: make a new filter and create a scope in your model to point filter.
To make a new Filter:
Example:
and configure your filter options according to your preference (read here)
Now, is need make a scope in your model, example:
Configure
zFilters supports three filters type: simple, relation and complex.
Simple Filters:
Simple Filter is a whereIn condition, when you make a simple filter you is saying.
Let's assume that your user table has the column "department_id", to make a simple filter you just need to reference how the name of the filter option will be, let's call it "departments" and the column, which would be "department_id"
Now the array of values or single value you send in $filters['departments'] will be filtered in whereIn condition on the simple filter
Relation Filters:
Relation Filter is a whereIn condition in a relation, when you make a relation filter you is saying.
Let's assume that your User model has the relation with department (departments()), to create a relationship filter where we must get all the users that the department belongs to manager 1 or 2 we can do this:
Now the array of values or single value you send in $filters['departments_manager'] will be filtered in whereIn condition in departments relation on manager_id column.
Complex Filters
The complex filter can deal with more specific conditions, it accepts a callback function and you can filter however you want, let's go to another example. Assuming your same user table has a name column and a summary column and you expect to do a complex search for both conditions by value, one way to do it would be:
The complex filter option named 'search' will execute the function, the value of $q will be the query builder being formed and the second parameter, $filterValue will be automatically implemented to what is sent in $filters['search'], as it is a callback function you can work on it too, manipulate the values sent, as if it were inside the query builder itself.
License
The MIT License (MIT). Please see License File for more information
Made with ♥ by Kayck Matias