abelaguiar / filter-laravel
Make filters in laravel
Requires
- php: ^8.0
- illuminate/console: @dev
- illuminate/database: @dev
- illuminate/http: @dev
- illuminate/support: @dev
Requires (Dev)
- phpunit/phpunit: ~4.0
README
The abelaguiar/filter-laravel
package provides easy to use functions to simples filters in laravel.
Install Package
composer require abelaguiar/filter-laravel
Use php artisan
to view the list of commands associated with filters.
Create filters:
php artisan filter:model <Model>
Create field:
php artisan filter:field <Name>
When creating a filter, inside the class we have an array, where you will put the fields you want to use as filters in your model.
Example filter class with fields implemention:
use App\Filters\Fields\TitleField; use AbelAguiar\Filter\AbstractFilter; class PostClass extends AbstractFilter { protected $filters = [ 'title' => TitleField::class ]; }
Example fields class:
class TitleField { public function filter($builder, $value) { return $builder->where('title', $value); } }
Created the filters, in the model that you want to connect filters, you will put:
use AbelAguiar\Filter\RequestFilter; class Post { use RequestFilter; ...
If you want to set up a different filter path, use the variable below within the model:
protected static $filter = 'App\Filters\PostFilter'; ...
Finally, when calling your model anywhere in your application, just call the method filter
by passing the request, thus returning all data from the buca, as in the example below:
Post::filter($request)->get()