1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SaasReady\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\JsonResponse; |
6
|
|
|
use Illuminate\Routing\Controller; |
7
|
|
|
use SaasReady\Http\Requests\DynamicSetting\DynamicSettingIndexRequest; |
8
|
|
|
use SaasReady\Http\Requests\DynamicSetting\DynamicSettingStoreRequest; |
9
|
|
|
use SaasReady\Http\Requests\DynamicSetting\DynamicSettingUpdateRequest; |
10
|
|
|
use SaasReady\Http\Responses\DynamicSettingResource; |
11
|
|
|
use SaasReady\Models\DynamicSetting; |
|
|
|
|
12
|
|
|
|
13
|
|
|
class DynamicSettingsController extends Controller |
14
|
|
|
{ |
15
|
|
|
public function index(DynamicSettingIndexRequest $request): JsonResponse |
16
|
|
|
{ |
17
|
|
|
$dynamicSettings = DynamicSetting::orderBy('created_at', 'DESC') |
18
|
|
|
->when($request->input('source_type'), fn ($q) => $q->where([ |
19
|
|
|
'model_type' => $request->input('source_type'), |
20
|
|
|
])) |
21
|
|
|
->paginate($request->integer('limit') ?: 10); |
22
|
|
|
|
23
|
|
|
return DynamicSettingResource::collection($dynamicSettings)->response(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function show(DynamicSetting $dynamicSetting): JsonResponse |
27
|
|
|
{ |
28
|
|
|
return (new DynamicSettingResource($dynamicSetting))->response(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function store(DynamicSettingStoreRequest $request): JsonResponse |
32
|
|
|
{ |
33
|
|
|
$relatedModel = $request->getRelatedModel(); |
34
|
|
|
|
35
|
|
|
$dynamicSetting = DynamicSetting::create([ |
36
|
|
|
...$request->validated(), |
37
|
|
|
'model_id' => $relatedModel->getKey(), |
38
|
|
|
'model_type' => $relatedModel->getMorphClass(), |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
return new JsonResponse([ |
42
|
|
|
'uuid' => $dynamicSetting->uuid, |
43
|
|
|
], 201); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function update( |
47
|
|
|
DynamicSettingUpdateRequest $request, |
48
|
|
|
DynamicSetting $dynamicSetting |
49
|
|
|
): JsonResponse { |
50
|
|
|
$relatedModel = $request->getRelatedModel(); |
51
|
|
|
|
52
|
|
|
$dynamicSetting->update([ |
53
|
|
|
...$request->validated(), |
54
|
|
|
'model_id' => $relatedModel?->getKey() ?? $dynamicSetting->model_id, |
55
|
|
|
'model_type' => $relatedModel?->getMorphClass() ?? $dynamicSetting->model_type, |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
return new JsonResponse([ |
59
|
|
|
'uuid' => $dynamicSetting->uuid, |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function destroy(DynamicSetting $dynamicSetting): JsonResponse |
64
|
|
|
{ |
65
|
|
|
if ($dynamicSetting->model_id === null && $dynamicSetting->model_type === null) { |
66
|
|
|
return new JsonResponse([ |
67
|
|
|
'error' => 'Global dynamic setting can not be deleted', |
68
|
|
|
], 400); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$dynamicSetting->delete(); |
72
|
|
|
|
73
|
|
|
return new JsonResponse(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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