Download the PHP package mhamzeh/presenter-filter without Composer
On this page you can find all versions of the php package mhamzeh/presenter-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package presenter-filter
Presenter-Filter Laravel
Introduction
The package allows you to create two types of classes: filter class and presenter class
Filter
This package allows you to easily handle database filtering through query strings.
example: /users?status=1&name='kami'
Presenter
Sometimes our models get too fat, and that can make our development a lot harder. In this case, we use a second class that has the same function as the model and is used as a second model, and the Harrow method can be included in this class.
Installation
you can install the package via composer:
You Must by publishing configuration by issuing following artisan command .
Usage
You have access to two commands and you can use them to create your own filter and presenter classes
make:filter command
You can use the following command to create a new filter.
This will create a new filter in the app/Filters directory.
options:
1-You can add the model to the command
Used by default Models folder If you have saved models elsewhere, change the config Modules of this folder
make:presenter Command
You can use the following command to create a new Presenter
options:
1- You can add the model to command
Example With Filter
Let's say you want to use filterable on User model. You will have to create the filter class App/Filters/PostFilter.php ()
If you use the --model option, filterable will be added directly to the model
Now you need to add local scope to your model if you have not used the --model option:
Finaly, call the scope in controller like so:
Example With Presenter
Let's say you want to use Presentable And introduce the presenter class on User model. You will have to create the filter class App/Presenter/UserPresenter.php ()
If you use the --model option, Presentable and presenter class will be added directly to the model
Now you need to add local scope to your model if you have not used the --model option:
Finally you can use this method in your Blade or Api Resources or Controller for example Blade:
in Api Resources: