clientService = $clientService; // } // public function index(): AnonymousResourceCollection // { // $clients = $this->clientService->getAll(); // return ClientResource::collection($clients); // } // public function store(ClientRequest $request): ClientResource // { // $client = $this->clientService->create($request->validated()); // return new ClientResource($client->load('user')); // } // public function show(string $id): ClientResource // { // $client = $this->clientService->findById($id); // return new ClientResource($client); // } // public function update(ClientRequest $request, string $id): JsonResponse // { // $this->clientService->update($request->validated(), $id); // return response()->json(['message' => 'Client updated successfully']); // } // public function destroy(string $id): JsonResponse // { // $this->clientService->delete($id); // return response()->json(['message' => 'Client deleted successfully']); // } public function __construct(protected ClientService $service) {} public function index(): JsonResponse { $items = $this->service->getAll(); return $this->successResponse( payload: ClientResource::collection($items), ); } public function store(ClientRequest $request): JsonResponse { $item = $this->service->create($request->validated()); return $this->successResponse( payload: new ClientResource($item), message: __("messages.created"), code: 201, ); } public function show(int $id): JsonResponse { $item = $this->service->findById($id); return $this->successResponse(payload: new ClientResource($item)); } public function update(ClientRequest $request, int $id): JsonResponse { $item = $this->service->update($request->validated(), $id); return $this->successResponse( payload: new ClientResource($item), message: __("messages.updated"), ); } public function destroy(int $id): JsonResponse { $this->service->delete($id); return $this->successResponse( message: __("messages.deleted"), code: 204, ); } }