integration Google No CAPTCHA reCAPTCHA using Laravel
Google reCaptcha in Laravel application Example
integration Google No CAPTCHA reCAPTCHA using Laravel Code – Setup Google Captcha PHP Nomally any simple Google captcha protect create we new websites from all the comments spamming.Google has recently new announced new service provided to prevent your website from menas fake spammers and malware attackers. It’s completely new reCAPTCHA API called fully check “Are you a Robot?”. and second one They named it “NO CAPTCHA reCAPTCHA”. It is designed to simple prevent we websites check from all the attackers and all the spammer.
Don’t forget to replace please <–Your Secret Key–> and with your own secret key.
Integrate simple Google reCAPTCHA into your Website
To integrate “Google reCAPTCHA” into your new website or web-apps you need to put simple Google check reCAPTCHA it in Client Side as well as in Server side. browser In Client HTML DOM images or sign page you need to simple integrate this all the line before
tag.Step1: pakainfo/no-captcha package installation
I will show you recommend Composer using cmd that is most widely used as a dependecy on the google manager for PHP simple packages. To add this plugin dependency using cmd – the command, run the following simple command from we project structure directory.
composer require pakainfo/no-captcha
Now simple add the service manager provider to the providers all the array list in following directory path config/app.php
config/app.php
pakainfo\NoCaptcha\NoCaptchaServiceProvider::class
Step2: simple Add and Get NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY
Add these changes line in we .env file in root directory path
NOCAPTCHA_SECRET=[your secret-key] - 6LeIxAcT7978989GG-vFI1TnR12548FuojJ4WifJWe NOCAPTCHA_SITEKEY=[your site-key] - 6LeIxAcT898656596JcZVRqyHh71UMIEGN12356iZKhI
To get simple your secret-key and your site-key click here Recaptcha Admin
Step3: Add Route in this directory and Controller functions using laravel
Route::get('captcha-form-validation',array('as'=>'google.get-recaptcha-validation-form','uses'=>'FileController@livegetCapcha')) ; Route::post('captcha-form-validation',array('as'=>'google.post-recaptcha-validation','uses'=>'FileController@mygetCapchaform')) ;
Add these simple two methods in we controller using laravel.
public function livegetCapcha(){ return view('files.captchaform'); } public function mygetCapchaform(Request $request){ $this->validate($request, [ 'name' => 'required', 'email'=>'required|email', 'mobile'=>'required|numeric|digits:10', 'comments' => 'required', 'g-recaptcha-response' => 'required|captcha', ]); }
Step4: Add simple create a Blade File
Now create a simple blade file using cmd where you have to allowed validate we form using simple Google no-captcha recaptcha
resources/views/files/captchaform.blade.phpSimple Google reCaptcha Validation Example{!! Form::open(array('route' => 'google.post-recaptcha-validation','method'=>'POST','files'=>true,'id'=>'liveform')) !!}Name: {!! Form::text('name', null, array('placeholder' => 'Name','class' => 'form-control')) !!} {!! $errors->first('name', ':message
') !!}Email: {!! Form::text('email', null, array('placeholder' => 'Email','class' => 'form-control')) !!} {!! $errors->first('email', ':message
') !!}mobile: {!! Form::text('mobile', null, array('placeholder' => 'Mobile No','class' => 'form-control')) !!} {!! $errors->first('mobile', ':message
') !!}comments: {!! Form::textarea('comments', null, array('placeholder' => 'comments','class' => 'form-control','style'=>'height:100px')) !!} {!! $errors->first('comments', ':message
') !!}Captcha: {!! app('captcha')->display() !!} {!! $errors->first('g-recaptcha-response', ':message
') !!}{!! Form::close() !!}
Don’t forget to add script file in head section.