First, install anhskohbo/no-captcha Package for Google reCaptcha code. Using this Package, we can generate reCaptcha code for our Application.
composer require anhskohbo/no-captcha
Type below command to Publish Config File
php artisan vendor:publish --provider="Anhskohbo\NoCaptcha\NoCaptchaServiceProvider"
In Env file add these lines
NOCAPTCHA_SECRET=6LfAxnYUAAAAAMFIDoHDyukSi4yHcYZp8q5WdB2m
NOCAPTCHA_SITEKEY=6LfAxnYUAAAAAH5JZ5xlK_iTjjkbdupMuvKeszYZ
Add this lines to your register or login page.
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
<label for="ReCaptcha">Recaptcha:</label>
{!! NoCaptcha::renderJs() !!}
{!! NoCaptcha::display() !!}
</div>
</div>
Add in LoginContorller.php
protected function validateLogin(Request $request)
{
$this->validate($request,[
'email' => ['required', 'string', 'email'],
'password' => ['required', 'string'],
'g-recaptcha-response' => ['required','captcha'],
]);
}