Расширение валидатора неявно не срабатывает в AppServiceProvider

Я пытаюсь подтвердить свой ответ recaptcha в своей форме, разместив ссылку на URL-адрес, предоставленный Google, однако, когда я пытаюсь запустить его через AppServiceProvider, он совсем не попадает в него и пропускает его. Я вижу, что валидатор работает с FormRequest, но по какой-то причине он не запускает функцию проверки на моем CaptchaValidator

Вот мой AppServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Schema::defaultStringLength(191);

if ($this->app->environment() == 'production') {
\URL::forceScheme('https');
}

\Validator::extendImplicit('recaptcha', 'App\Validation\CaptchaValidator@Check',
'You have not passed the recaptcha.');
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
if ($this->app->environment() !== 'production') {
$this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
}
}
}

CaptchaValidator

<?php

namespace App\Validation;

use GuzzleHttp\Client;

class CaptchaValidator
{
public function Check($attribute, $value, $parameters)
{
$parameters = http_build_query([
'secret' => env('RECAPTCHA_PRIVATE_KEY'),
'remoteip' => app('request')->getClientIp(),
'response' => $value,
]);

$url = 'https://www.google.com/recaptcha/api/siteverify?' . $parameters;

$client = new Client();
$response = $client->request('post', $url);

try {
$results = json_decode($response->getBody()->getContents());

return $results->success;
} catch (\Exception $exception) {
}

return true;
}
}

Запрос формы с валидацией

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RedeemRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'g-recaptcha-response' => 'required|recaptcha',
];
}
}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector