1 | <?php |
||
2 | |||
3 | namespace Zgabievi\KendoGridState\Scopes; |
||
4 | |||
5 | use Illuminate\Database\Eloquent\Model; |
||
6 | use Illuminate\Database\Eloquent\Scope; |
||
7 | use Illuminate\Database\Eloquent\Builder; |
||
8 | use Zgabievi\KendoGridState\Filters\Skip; |
||
9 | use Zgabievi\KendoGridState\Filters\Sort; |
||
10 | use Zgabievi\KendoGridState\Filters\Take; |
||
11 | use Zgabievi\KendoGridState\Filters\Group; |
||
12 | use Zgabievi\KendoGridState\Filters\State; |
||
13 | use Zgabievi\KendoGridState\Filters\Filter; |
||
14 | |||
15 | class KendoScope implements Scope |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | public static $filters = [ |
||
21 | 'filter' => Filter::class, |
||
22 | 'group' => Group::class, |
||
23 | 'skip' => Skip::class, |
||
24 | 'sort' => Sort::class, |
||
25 | 'take' => Take::class, |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * Apply the scope to a given Eloquent query builder. |
||
30 | * |
||
31 | * @param Builder $builder |
||
32 | * @param Model $model |
||
33 | * @return \Illuminate\Database\Query\Builder|Builder |
||
34 | */ |
||
35 | public function apply(Builder $builder, Model $model) |
||
36 | { |
||
37 | return (new State($this->kendoRequest()))->filter($builder); |
||
0 ignored issues
–
show
|
|||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @return array |
||
42 | */ |
||
43 | protected function kendoRequest() |
||
44 | { |
||
45 | return array_filter( |
||
46 | request()->only( |
||
47 | array_keys(self::$filters) |
||
48 | ) |
||
49 | ); |
||
50 | } |
||
51 | } |
||
52 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: