Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 5ceac2f

Browse files
committed
Add "empty_message" value to empty default message (removing "trans" helper)
1 parent 0fe4241 commit 5ceac2f

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

config/recaptcha.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright (c) 2017 - present
45
* LaravelGoogleRecaptcha - recaptcha.php
@@ -110,6 +111,24 @@
110111
*/
111112
'api_domain' => 'www.google.com',
112113

114+
/**
115+
*
116+
* Set `true` when the error message must be null
117+
* @since v5.1.0
118+
* Default false
119+
*
120+
*/
121+
'empty_message' => false,
122+
123+
/**
124+
*
125+
* Set either the error message or the errom message translation key
126+
* @since v5.1.0
127+
* Default 'validation.recaptcha'
128+
*
129+
*/
130+
'error_message_key' => 'validation.recaptcha',
131+
113132
/**
114133
*
115134
* g-recaptcha tag attributes and grecaptcha.render parameters (v2 only)

src/ReCaptchaServiceProvider.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright (c) 2017 - present
45
* LaravelGoogleRecaptcha - ReCaptchaServiceProvider.php
@@ -39,19 +40,22 @@ public function boot()
3940
$this->publishes([
4041
__DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'),
4142
], 'config');
42-
4343
}
4444

4545
/**
4646
* Extends Validator to include a recaptcha type
4747
*/
4848
public function addValidationRule()
4949
{
50+
$message = null;
5051

52+
if (!config('recaptcha.empty_message')) {
53+
$message = trans(config('recaptcha.error_message_key'));
54+
}
5155
Validator::extendImplicit(recaptchaRuleName(), function ($attribute, $value) {
5256

5357
return app('recaptcha')->validate($value);
54-
}, trans('validation.recaptcha'));
58+
}, $message);
5559
}
5660

5761
/**
@@ -63,7 +67,8 @@ public function register()
6367
{
6468

6569
$this->mergeConfigFrom(
66-
__DIR__ . '/../config/recaptcha.php', 'recaptcha'
70+
__DIR__ . '/../config/recaptcha.php',
71+
'recaptcha'
6772
);
6873

6974
$this->registerReCaptchaBuilder();
@@ -109,10 +114,10 @@ protected function registerReCaptchaBuilder()
109114
$recaptcha_class = '';
110115

111116
switch (config('recaptcha.version')) {
112-
case 'v3' :
117+
case 'v3':
113118
$recaptcha_class = ReCaptchaBuilderV3::class;
114119
break;
115-
case 'v2' :
120+
case 'v2':
116121
$recaptcha_class = ReCaptchaBuilderV2::class;
117122
break;
118123
case 'invisible':
@@ -121,8 +126,6 @@ protected function registerReCaptchaBuilder()
121126
}
122127

123128
return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'));
124-
125129
});
126130
}
127-
128131
}

0 commit comments

Comments
 (0)