A Blog Of Random Coding Techniques & Experiments Robert Askam

How to add Captcha to the Laravel 5.5 Registration Process Post How to add Captcha to the Laravel 5.5 Registration Process 1 year ago

This will help you stop spam registrations on your site. A simple Captcha Registration process.

Terminal

composer require mews/captcha

App.php

'providers' => [Mews\Captcha\CaptchaServiceProvider::class,
'aliases' => [
'Captcha' => Mews\Captcha\Facades\Captcha::class,

App.Js

jQuery(".btn-refresh").click(function(){
Jquery.ajax({
type: 'GET',
url: '/refresh_captcha',
success: function(data) {
Jquery(".captcha span").html(data.captcha);
}
})
})

Register Controller

protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'captcha' => 'required|captcha'
]);
}

Web.php

Route::get('refresh_captcha', 'HomeController@refreshCaptcha')->name('refresh_captcha');

HomeController

public function refreshCaptcha()
{
return response()->json(['captcha' => captcha_img()]);
}

Register Blade