1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\QueryBuilder; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
|
8
|
|
|
class QueryBuilderServiceProvider extends ServiceProvider |
9
|
|
|
{ |
10
|
|
|
public function boot() |
11
|
|
|
{ |
12
|
|
|
$this->loadTranslationsFrom( |
13
|
|
|
__DIR__.'/../lang', |
14
|
|
|
'query-builder' |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
$this->publishes([ |
18
|
|
|
__DIR__.'/../lang' => resource_path('lang/vendor/query-builder'), |
19
|
|
|
]); |
20
|
|
|
|
21
|
|
|
Request::macro('includes', function ($include = null) { |
22
|
|
|
$includeParts = $this->query('include'); |
|
|
|
|
23
|
|
|
|
24
|
|
|
if (! is_array($includeParts)) { |
25
|
|
|
$includeParts = explode(',', strtolower($this->query('include'))); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$includes = collect($includeParts)->filter(); |
29
|
|
|
|
30
|
|
|
if (is_null($include)) { |
31
|
|
|
return $includes; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $includes->contains(strtolower($include)); |
35
|
|
|
}); |
36
|
|
|
|
37
|
|
|
Request::macro('filters', function ($filter = null) { |
38
|
|
|
$filterParts = $this->query('filter'); |
|
|
|
|
39
|
|
|
|
40
|
|
|
if (! $filterParts) { |
41
|
|
|
return collect(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$filters = collect($filterParts)->filter(function ($filter) { |
45
|
|
|
return ! is_null($filter); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$filters = $filters->map(function ($value) { |
49
|
|
|
if (str_contains($value, ',')) { |
50
|
|
|
return explode(',', $value); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($value === 'true') { |
54
|
|
|
return true; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($value === 'false') { |
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $value; |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
if (is_null($filter)) { |
65
|
|
|
return $filters; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $filters->get(strtolower($filter)); |
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
Request::macro('sort', function ($default = null) { |
72
|
|
|
return $this->query('sort', $default); |
|
|
|
|
73
|
|
|
}); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.