'Fetch Users', 'message' => 'You have successfully retrieved the user' ]; } /** @var CanFetchUser */ private $canFetchUser; /** @var FetchesUser */ private $fetchessUser; /** * FetchUserLogic constructor. * @param CanFetchUser $canFetchUser * @param FetchesUser $fetchessUser */ public function __construct(CanFetchUser $canFetchUser, FetchesUser $fetchessUser) { $this->canFetchUser = $canFetchUser; $this->fetchessUser = $fetchessUser; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { $this->canFetchUser->passes(); $query = $this->fetchessUser->execute(['id' => $request->input('user_id')]); return $this->collectionResponse(UserResource::collection($query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }