|
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
|
|
|
Request::macro('includes', function ($include = null) { |
|
13
|
|
|
$includeParts = $this->query('include'); |
|
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
if (! is_array($includeParts)) { |
|
16
|
|
|
$includeParts = explode(',', strtolower($this->query('include'))); |
|
|
|
|
|
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
$includes = collect($includeParts)->filter(); |
|
20
|
|
|
|
|
21
|
|
|
if (is_null($include)) { |
|
22
|
|
|
return $includes; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
return $includes->contains(strtolower($include)); |
|
26
|
|
|
}); |
|
27
|
|
|
|
|
28
|
|
|
Request::macro('filters', function ($filter = null) { |
|
29
|
|
|
$filterParts = $this->query('filter'); |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
if (! $filterParts) { |
|
32
|
|
|
return collect(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$filters = collect($filterParts)->filter(function ($filter) { |
|
36
|
|
|
return ! is_null($filter); |
|
37
|
|
|
}); |
|
38
|
|
|
|
|
39
|
|
|
$filters = $filters->map(function ($value) { |
|
40
|
|
|
if (str_contains($value, ',')) { |
|
41
|
|
|
return explode(',', $value); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if ($value === 'true') { |
|
45
|
|
|
return true; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($value === 'false') { |
|
49
|
|
|
return false; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $value; |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
if (is_null($filter)) { |
|
56
|
|
|
return $filters; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $filters->get(strtolower($filter)); |
|
60
|
|
|
}); |
|
61
|
|
|
|
|
62
|
|
|
Request::macro('sort', function ($default = null) { |
|
63
|
|
|
return $this->query('sort', $default); |
|
|
|
|
|
|
64
|
|
|
}); |
|
65
|
|
|
|
|
66
|
|
|
Request::macro('sorts', function ($default = null) { |
|
67
|
|
|
$sortParts = $this->sort(); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
if (! is_array($sortParts)) { |
|
70
|
|
|
$sortParts = explode(',', $sortParts); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$sorts = collect($sortParts)->filter(); |
|
74
|
|
|
|
|
75
|
|
|
if ($sorts->isNotEmpty()) { |
|
76
|
|
|
return $sorts; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return collect($default)->filter(); |
|
80
|
|
|
}); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
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.