createUserInvitation = $createUserInvitation; $this->canSendAccountInvitation = $canSendAccountInvitation; } /** * @param Request $request * @return JsonResponse * @throws InternalServerErrorException */ public function execute(Request $request) { try { $object = new UserInvitationObject($request->get('role_id'), $request->get('email')); if($this->canSendAccountInvitation->execute($object)){ $invitation = $this->createUserInvitation->execute($object); event(new UserInvited($invitation)); return new JsonResponse("Invitation have been sent!", HttpStatus::RESOURCE_CREATED); } } catch (ResourceConflictException $exception) { throw new InternalServerErrorException("Failed to send user invitation because {$exception->getMessage()}"); } } }