ibehbudov/laravel-google-captcha

Google Captcha rule for Laravel validation

dev-master 2022-08-24 07:36 UTC

This package is auto-updated.

Last update: 2024-10-24 12:21:08 UTC


README

##Google Captcha for Laravel

Installation

composer require ibehbudov/laravel-google-captcha

Publish vendor files

php artisan vendor:publish --tag=google-captcha

Secret key

Open config/google-captcha.php file and edit

return [
    'secret_key'   =>  'google_secret_key'
];

Usage

Inside controller

$request->validate([
    'g-recaptcha-response'  =>  new GoogleCaptchaRule()
]);

Inside rule

public function rules()
{
    return [
        'g-recaptcha-response'  =>  new GoogleCaptchaRule()
    ];
}

In somewhere as you want

$googleCaptcha = app(GoogleCaptcha::class);

$googleCaptcha->validate($request->post('g-recaptcha-response'));

if($googleCaptcha->fail()) {
    return $googleCaptcha->getErrorMessage();
}
else {
    // code goes here
}