| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace App\Http\Controllers;
- use App\Http\Requests\UserDependentRequest;
- use App\Http\Resources\UserDependentResource;
- use App\Services\UserDependentService;
- use Illuminate\Http\JsonResponse;
- class UserDependentController extends Controller
- {
- public function __construct(protected UserDependentService $service) {}
- public function indexByUser(int $userId): JsonResponse
- {
- $items = $this->service->getAllByUser($userId);
- return $this->successResponse(payload: UserDependentResource::collection($items));
- }
- public function store(UserDependentRequest $request): JsonResponse
- {
- $item = $this->service->create($request->validated());
- return $this->successResponse(
- payload: new UserDependentResource($item),
- message: __('messages.created'),
- code: 201,
- );
- }
- public function show(int $id): JsonResponse
- {
- $item = $this->service->findById($id);
- return $this->successResponse(payload: new UserDependentResource($item));
- }
- public function update(UserDependentRequest $request, int $id): JsonResponse
- {
- $item = $this->service->update($id, $request->validated());
- return $this->successResponse(
- payload: new UserDependentResource($item),
- message: __('messages.updated'),
- );
- }
- public function destroy(int $id): JsonResponse
- {
- $this->service->delete($id);
- return $this->successResponse(message: __('messages.deleted'), code: 204);
- }
- }
|