key = $key; } /** * Run the validation rule. * * @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail */ public function validate(string $attribute, mixed $value, Closure $fail): void { // // 从容器获取 Service(便于测试和依赖注入) $captchaService = App::make(CaptchaService::class); if (!$captchaService->testPhrase($this->key, $value)) { $fail('验证码错误,请重新输入'); } } }