addValidationRule(); $this->publishes([ __DIR__ . '/../config/captcha.php' => config_path('captcha.php'), ], 'config'); if (config('captcha.enable_blade_captcha')) { Blade::directive('captcha', function () { return ""; }); } } /** * Extends Validator to include a captcha type */ public function addValidationRule(): Void { $message = trans(config('captcha.error_message_key')); Validator::extendImplicit(config('captcha.rule_name'), function ($attribute, $value) { if (!is_string($value)) { return false; } return app(CaptchaService::class)->validate($value, request()->userAgent()); }, $message); } /** * Register the service provider. * * @return void */ public function register(): Void { $this->mergeConfigFrom( __DIR__ . '/../config/captcha.php', 'captcha' ); $this->app->singleton(CaptchaService::class, function (Application $app) { return new CaptchaService( privateToken: config('captcha.api_private_token', ''), domainApi: config('captcha.api_domain', ''), curlTimeout: config('captcha.curl_timeout', ''), ); }); } }