1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SaasReady\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
|
6
|
|
|
use Illuminate\Routing\Controller; |
|
|
|
|
7
|
|
|
use Illuminate\Support\Facades\Event; |
|
|
|
|
8
|
|
|
use SaasReady\Events\Currency\CurrencyCreated; |
9
|
|
|
use SaasReady\Events\Currency\CurrencyDeleted; |
10
|
|
|
use SaasReady\Events\Currency\CurrencyUpdated; |
11
|
|
|
use SaasReady\Http\Requests\Currency\CurrencyDestroyRequest; |
12
|
|
|
use SaasReady\Http\Requests\Currency\CurrencyIndexRequest; |
13
|
|
|
use SaasReady\Http\Requests\Currency\CurrencyShowRequest; |
14
|
|
|
use SaasReady\Http\Requests\Currency\CurrencyStoreRequest; |
15
|
|
|
use SaasReady\Http\Requests\Currency\CurrencyUpdateRequest; |
16
|
|
|
use SaasReady\Http\Responses\CurrencyResource; |
17
|
|
|
use SaasReady\Models\Currency; |
|
|
|
|
18
|
|
|
|
19
|
|
|
class CurrencyController extends Controller |
20
|
|
|
{ |
21
|
|
|
public function index(CurrencyIndexRequest $request): JsonResponse |
22
|
|
|
{ |
23
|
|
|
$currencies = Currency::orderBy('name') |
24
|
|
|
->when($request->wantsActivated(), fn ($q) => $q->whereNotNull('activated_at')); |
25
|
|
|
|
26
|
|
|
return CurrencyResource::collection( |
27
|
|
|
$request->wantsPagination() |
28
|
|
|
? $currencies->paginate($request->getLimit()) |
29
|
|
|
: $currencies->get() |
30
|
|
|
)->toResponse($request); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function show(CurrencyShowRequest $request, Currency $currency): JsonResponse |
34
|
|
|
{ |
35
|
|
|
return (new CurrencyResource($currency))->toResponse($request); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function store(CurrencyStoreRequest $request): JsonResponse |
39
|
|
|
{ |
40
|
|
|
$currency = Currency::create([ |
41
|
|
|
...$request->validated(), |
42
|
|
|
'activated_at' => $request->boolean('is_active') ? now() : null, |
|
|
|
|
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
Event::dispatch(new CurrencyCreated($currency)); |
46
|
|
|
|
47
|
|
|
return new JsonResponse([ |
48
|
|
|
'uuid' => $currency->uuid, |
49
|
|
|
], 201); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function update(CurrencyUpdateRequest $request, Currency $currency): JsonResponse |
53
|
|
|
{ |
54
|
|
|
$currency->update([ |
55
|
|
|
...$request->validated(), |
56
|
|
|
'activated_at' => $request->boolean('is_active') ? now() : null, |
|
|
|
|
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
Event::dispatch(new CurrencyUpdated($currency)); |
60
|
|
|
|
61
|
|
|
return new JsonResponse([ |
62
|
|
|
'uuid' => $currency->uuid, |
63
|
|
|
]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function destroy(CurrencyDestroyRequest $request, Currency $currency): JsonResponse |
67
|
|
|
{ |
68
|
|
|
$currency->delete(); |
69
|
|
|
|
70
|
|
|
Event::dispatch(new CurrencyDeleted($currency)); |
71
|
|
|
|
72
|
|
|
return new JsonResponse(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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