repository = $repository; $this->user = $user; } /** * @param UserInvitationObject $object * @return UserInvitation|null * @throws ResourceConflictException */ public function execute(UserInvitationObject $object): ?UserInvitation { // ensure that there is not already an invitation for the email $existingInvitations = $this->repository->where('email', $object->getInviteeEmail())->get(); if ($existingInvitations->count() !== 0) { throw new ResourceConflictException("An existing invitation already exists for the email {$object->getInviteeEmail()}"); } $model = $this->repository->create([ 'email' => $object->getInviteeEmail(), 'hash' => Common::generateRandomHash(50), 'role_id' => $object->getRole(), 'sender_id' => 1,//$this->user->getAuthIdentifier(), 'is_complete' => false, ]); return $model; } }