ibehbudov/laravel-google-captcha

Google Captcha rule for Laravel validation

Installs: 34

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/ibehbudov/laravel-google-captcha

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

This package is auto-updated.

Last update: 2025-12-24 14:59:52 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
}