[ 'required', 'string', 'email', 'max:255', Rule::unique(User::class), function (string $attribute, mixed $value, Closure $fail) { if (!self::emailIsValid($value)) { $fail(__('This domain is blacklisted.')); } }, ], 'password' => $this->passwordRules(), 'token_name' => 'string|min:3|max:50', ]; foreach ($appRules as $key => $rules) { $commonRules[$key] = array_map(function ($rule) { if (str_contains($rule, '\\')) { $namespace = "\\$rule"; return new $namespace(); } return $rule; }, $rules); } $data = Validator::make($input, $commonRules)->validate(); return (new CreateUser())->execute($data); } public static function emailIsValid(string $email): bool { $blacklistedDomains = explode( ',', settings('auth.domain_blacklist', ''), ); if ($blacklistedDomains) { $domain = explode('@', $email)[1] ?? null; if ($domain && in_array($domain, $blacklistedDomains)) { return false; } } return true; } }