Skip to content

Commit

Permalink
Add custom validation rule during validation resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewnessworthy committed Mar 8, 2018
1 parent d182f11 commit 971e4e3
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/RecaptchaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class RecaptchaServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->addValidator();

$this->loadViewsFrom(__DIR__ . '/views', 'recaptcha');
}

Expand All @@ -35,12 +33,21 @@ public function boot()
*/
public function addValidator()
{
$this->app->validator->extendImplicit('recaptcha', function ($attribute, $value, $parameters) {
$captcha = app('recaptcha.service');
$challenge = app('request')->input($captcha->getResponseKey());

return $captcha->check($challenge, $value);
}, 'Please ensure that you are a human!');
$this->app->resolving(
'validator',
function ($validator) {
$validator->extendImplicit(
'recaptcha',
function ($attribute, $value, $parameters) {
$captcha = app('recaptcha.service');
$challenge = app('request')->input($captcha->getResponseKey());

return $captcha->check($challenge, $value);
},
'Please ensure that you are a human!'
);
}
);
}

/**
Expand All @@ -52,6 +59,7 @@ public function register()
{
$this->handleConfig();
$this->bindRecaptcha();
$this->addValidator();
}

protected function bindRecaptcha()
Expand Down Expand Up @@ -81,7 +89,7 @@ protected function bindRecaptcha()

protected function handleConfig()
{
$packageConfig = __DIR__ . '/config/recaptcha.php';
$packageConfig = __DIR__ . '/config/recaptcha.php';
$destinationConfig = config_path('recaptcha.php');

$this->publishes([
Expand Down

0 comments on commit 971e4e3

Please sign in to comment.