'Created Department', 'message' => 'You have successfully created a new Department' ]; } /** @var CanCreateDepartment */ private $canCreateDepartment; /** @var CreatesDepartment */ private $createsDepartment; /** * CreateDepartmentControllerLogic constructor. * @param CanCreateDepartment $canCreateDepartment * @param CreatesDepartment $createsDepartment */ public function __construct(CanCreateDepartment $canCreateDepartment, CreatesDepartment $createsDepartment) { $this->canCreateDepartment = $canCreateDepartment; $this->createsDepartment = $createsDepartment; } /** * @param Request $request * @return JsonResponse * @throws ErrorException */ public function logic(Request $request) : JsonResponse { try { $object = new DepartmentObject($request->input('name'), $request->input('description'), $request->input('head_id')); $this->canCreateDepartment->passes($object); $query = $this->createsDepartment->execute($object); return $this->resourceResponse(new DepartmentResource($query)); } catch (\Exception $exception){ throw new ErrorException($exception->getMessage(), $exception->getCode()); } } }