|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Malekbenelouafi\LaravelStatus\Scopes; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Scope; |
|
|
|
|
|
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class StatusScope implements Scope |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* All of the extensions to be added to the builder. |
|
13
|
|
|
* |
|
14
|
|
|
* @var array |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $extensions = ['WithInactive', 'WithoutInactive', 'OnlyInactive']; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Apply the scope to a given Eloquent query builder. |
|
20
|
|
|
* |
|
21
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $builder |
|
22
|
|
|
* @param \Illuminate\Database\Eloquent\Model $model |
|
23
|
|
|
* @return void |
|
24
|
|
|
*/ |
|
25
|
|
|
public function apply(Builder $builder, Model $model) |
|
26
|
|
|
{ |
|
27
|
|
|
$builder->where( |
|
28
|
|
|
$model->getQualifiedStatusColumn() , 1 |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Extend the query builder with the needed functions. |
|
34
|
|
|
* |
|
35
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $builder |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
public function extend(Builder $builder) |
|
39
|
|
|
{ |
|
40
|
|
|
foreach ($this->extensions as $extension) { |
|
41
|
|
|
$this->{"add{$extension}"}($builder); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Add the with-trashed extension to the builder. |
|
47
|
|
|
* |
|
48
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $builder |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function addWithInactive(Builder $builder) |
|
52
|
|
|
{ |
|
53
|
|
|
$builder->macro('withInactive', function (Builder $builder, $withInactive = true) { |
|
54
|
|
|
if (! $withInactive) { |
|
55
|
|
|
return $builder->withoutInactive(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $builder->withoutGlobalScope($this); |
|
59
|
|
|
}); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Add the without-trashed extension to the builder. |
|
65
|
|
|
* |
|
66
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $builder |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function addWithoutInactive(Builder $builder) |
|
70
|
|
|
{ |
|
71
|
|
|
$builder->macro('withoutInactive', function (Builder $builder) { |
|
72
|
|
|
$model = $builder->getModel(); |
|
73
|
|
|
|
|
74
|
|
|
$builder->withoutGlobalScope($this)->where( |
|
75
|
|
|
$model->getQualifiedStatusColumn() , 1 |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
return $builder; |
|
79
|
|
|
}); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Add the only-trashed extension to the builder. |
|
84
|
|
|
* |
|
85
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $builder |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
|
|
protected function addOnlyInactive(Builder $builder) |
|
89
|
|
|
{ |
|
90
|
|
|
$builder->macro('onlyInactive', function (Builder $builder) { |
|
91
|
|
|
$model = $builder->getModel(); |
|
92
|
|
|
|
|
93
|
|
|
$builder->withoutGlobalScope($this)->where( |
|
94
|
|
|
$model->getQualifiedStatusColumn() , 0 |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
|
|
return $builder; |
|
98
|
|
|
}); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths