'Updated Email', 'message' => 'Successfully updated email' ]; } /** * @var AssignEmployeeProcessor */ private $assignEmployeeProcessor; /** * @var GenerateEmailVerificationAttemptProcessor */ private $generateEmailVerificationAttemptProcessor; /** * AddNewMemberLogic constructor. * @param AssignEmployeeProcessor $assignEmployeeProcessor * @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor */ public function __construct(AssignEmployeeProcessor $assignEmployeeProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor) { $this->assignEmployeeProcessor = $assignEmployeeProcessor; $this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor; } /** * @param Request $request * @return JsonResponse * @throws ResourceConflictException * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request): JsonResponse { try { $user = Auth::user()->replicate(); $user->email = $request->input('email'); $user->status = ApprovalStatus::PENDING_VERIFICATION; $user->save(); } catch (QueryException $exception){ throw new ResourceConflictException('Unable to change your email address as it already exists'); } if($company = Auth::user()->company()->first()){ $Object = new EmploymentObject($company, $user); $this->assignEmployeeProcessor->execute($Object); } $this->generateEmailVerificationAttemptProcessor->execute($user); return $this->resourceResponse(new UserResource($user)); } }