1
- ## Laravel Advanced Filter
1
+ # Laravel Advanced Filter
2
2
This package allows you to filter on laravel models
3
3
4
4
You can choose fields to filtering and customize its data-types, aliases and excepted operators,
5
5
you can add/customize your request format, and you add new operators or overwrite the existed operators
6
6
7
7
8
- ### Installation
8
+ ## Installation
9
9
You can install the package via composer:
10
10
```
11
11
composer require asemalalami/laravel-advanced-filter
@@ -21,7 +21,7 @@ php artisan vendor:publish --provider="AsemAlalami\LaravelAdvancedFilter\Advance
21
21
These default config file that will be published:
22
22
[ Config File] ( https://github.com/AsemAlalami/Laravel-Advanced-Filter/blob/master/config/advanced_filter.php )
23
23
24
- ### Usage
24
+ ## Usage
25
25
- use ` HasFilter ` trait in the model
26
26
- add fields in the implementation of the abstract function ` setupFilter `
27
27
``` php
@@ -72,7 +72,7 @@ class Order extends Model
72
72
}
73
73
```
74
74
75
- ### Query Format
75
+ ## Query Format
76
76
Query format is the shape that you want to send your query(filters) in the request.
77
77
the package support 3 formats, and you can create a new format.
78
78
- ` json ` (default): the filters will send as json in the request
@@ -91,12 +91,12 @@ the package support 3 formats, and you can create a new format.
91
91
```
92
92
> set the default query format in the config file `query_format` attribute
93
93
94
- ##### Create a new query format:
94
+ #### Create a new query format:
95
95
- create a new class and extends it from `QueryFormat`: `class MyFormat extends QueryFormat`
96
96
- implement the abstract function `format` that returns `FilterRequest` object
97
97
- add the class to the config file in `custom_query_format` attribute: `'custom_query_format' => MyFormat::class,`
98
98
99
- ### Fields
99
+ ## Fields
100
100
Normal Field options:
101
101
- field name is the column name
102
102
- alias is the key that you want to send in the request
@@ -156,11 +156,11 @@ You can add fields to a model by using 4 functions:
156
156
$this->addCustomField('line_subtotal', '(`price` + `quantity`)', 'orderLines'); // inside "orderLines" relation
157
157
```
158
158
159
- ### Conjunction
159
+ ## Conjunction
160
160
Currently, the package support one conjunction between all fields
161
161
`and` | `or`, default conjunction attribute in the config file `default_conjunction`
162
162
163
- ### Operators
163
+ ## Operators
164
164
The package has many operators, you can create new operators,
165
165
and you can customize the operators aliases that you want to send in the request
166
166
- Equals (`=`, `equals`)
@@ -179,17 +179,17 @@ and you can customize the operators aliases that you want to send in the request
179
179
- NotEndsWith (`!$`, `notEndsWith`)
180
180
- Between (`><`, `between`)
181
181
182
- ##### Create a new Operator:
182
+ #### Create a new Operator:
183
183
- create a new class and extends it from `Operator`: `class MyOperator extends Operator`
184
184
- implement the abstract function `apply` and `getSqlOperator` (used as a default sql operator for count and custom field)
185
185
- add the class in the config file in `custom_operators` attribute: `'custom_operators' => [MyOperator::class => ['my-op', '*']],`
186
186
187
- ### Data Types:
187
+ ## Data Types:
188
188
- boolean
189
189
- date
190
190
- datetime
191
191
- numeric
192
192
- string
193
193
194
- ### Config
194
+ ## Config
195
195
[Config File ](https://github.com/AsemAlalami/Laravel-Advanced-Filter/blob/master/config/advanced_filter.php)
0 commit comments