In this tutorial,I will learn you how to use captcha code in laravel 8.you can easy and simply use captcha code in laravel 8.
In this post i give you very simple and from scratch of generate captcha code image as you can also see bellow preview. After complete this example you can found ui design like bellow preview, you have to just follow few step and find result:
Step 1: Install Laravel Project
First, you need to download the laravel fresh setup. Use this command then download laravel project setup :
composer create-project --prefer-dist laravel/laravel blog
Step 2: Install Captcha Module
This is the foundational step of this tutorial. In this step, we will install the Captcha package using the Composer package manager.
composer require mews/captcha
Setting Up Captcha Package
Captcha package needs to be registered in laravel application. Incorporate the Captcha service provider in the laravel app.
Open providers/config/app.php file and register the captcha service provider and aliases.
'providers' => [
'aliases' => [
'Captcha' => Mews\Captcha\Facades\Captcha::class,
Captcha Custom Config Settings
To manifest the custom captcha configuration, you must execute the below command:
php artisan vendor:publish
A list of options manifests on your terminal screen, select the “Mews\Captcha\CaptchaServiceProvider” list number and press enter.
Inside the config/captcha.php file, here you can enable or disable settings based on your requirement.
'default' => [
'length' => 5,
'width' => 120,
'height' => 36,
'quality' => 90,
'math' => true, //Enable Math Captcha
'expire' => 60, //Stateless/API captcha expiration
Step 3: Add Controller Method
index() – It loads the form template in the view with the captcha element.
capthcaFormValidate() – Validates the entire form, including the captcha input field.
reloadCaptcha() – It refreshes the captcha code or text.