File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Oooiik \LaravelQueryFilter \Filters ;
4
4
5
+ use http \Exception \BadMethodCallException ;
5
6
use Illuminate \Database \Eloquent \Builder ;
6
7
7
8
abstract class QueryFilter
@@ -11,6 +12,8 @@ abstract class QueryFilter
11
12
/** @var Builder */
12
13
protected $ realBuilder ;
13
14
15
+ public array $ default = [];
16
+
14
17
public function __construct (Builder $ builder )
15
18
{
16
19
$ this ->realBuilder = $ builder ;
@@ -31,9 +34,13 @@ public function filters()
31
34
32
35
public function apply (array $ validated )
33
36
{
37
+ $ validatedKeys = array_keys ($ validated );
38
+ $ defaultKeys = array_keys ($ this ->default );
34
39
foreach ($ this ->filters () as $ filter ) {
35
- if (in_array ($ filter , array_keys ( $ validated ) )) {
40
+ if (in_array ($ filter , $ validatedKeys )) {
36
41
$ this ->$ filter ($ validated [$ filter ], $ validated );
42
+ } elseif (in_array ($ filter , $ defaultKeys )) {
43
+ $ this ->$ filter ($ this ->default [$ filter ], $ validated );
37
44
}
38
45
}
39
46
return $ this ;
You can’t perform that action at this time.
0 commit comments