|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
|
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Terranet\Administrator\Contracts\Module; |
|
8
|
|
|
use Terranet\Administrator\Traits\Actions\BatchSkeleton; |
|
9
|
|
|
use Terranet\Administrator\Traits\Actions\Skeleton; |
|
10
|
|
|
|
|
11
|
|
|
class RemoveSelected |
|
12
|
|
|
{ |
|
13
|
|
|
use Skeleton, BatchSkeleton; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Delete collection elements. |
|
17
|
|
|
* |
|
18
|
|
|
* @param Model $eloquent |
|
19
|
|
|
* @param Request $request |
|
20
|
|
|
* |
|
21
|
|
|
* @return mixed |
|
22
|
1 |
|
*/ |
|
23
|
|
|
public function handle(Model $eloquent, Request $request) |
|
24
|
1 |
|
{ |
|
25
|
|
|
return $this->fetchForDelete($eloquent, $request) |
|
26
|
1 |
|
->each(function ($item) { |
|
27
|
1 |
|
return $this->canDelete($item) ? $item->delete() : $item; |
|
28
|
|
|
}); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Check if deletion of each item is authorized. |
|
33
|
|
|
* |
|
34
|
|
|
* @param Model $eloquent |
|
35
|
|
|
* |
|
36
|
|
|
* @return bool |
|
37
|
1 |
|
*/ |
|
38
|
|
|
protected function canDelete(Model $eloquent) |
|
39
|
1 |
|
{ |
|
40
|
|
|
/** @var Module $resource */ |
|
41
|
|
|
$resource = app('scaffold.module'); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
return $resource->actions()->authorize('delete', $eloquent); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param Model $eloquent |
|
48
|
1 |
|
* @param Request $request |
|
49
|
|
|
* |
|
50
|
1 |
|
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|Model[] |
|
|
|
|
|
|
51
|
1 |
|
*/ |
|
52
|
1 |
|
protected function fetchForDelete(Model $eloquent, Request $request) |
|
53
|
|
|
{ |
|
54
|
|
|
return $eloquent->newQueryWithoutScopes() |
|
55
|
|
|
->whereIn('id', $request->get('collection', [])) |
|
56
|
|
|
->get(); |
|
57
|
|
|
} |
|
58
|
1 |
|
|
|
59
|
|
|
/** |
|
60
|
1 |
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function icon() |
|
63
|
|
|
{ |
|
64
|
|
|
return 'fa-trash'; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
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