In todays's tutorial, we are going to learn how to intergrade captcha with our Laravel application. When we considering about the security of our application, it's play a major role to enhance our application's security. Basically captcha is something like a text on image which can be readable by humans. So, in this tutorial, we are implement captcha validation using mews/captcha package.
Install mews/captcha package
Firstly, we need to install required Laravel package, which we are going to use in this tutorial. As I previously mentioned, we are used mews/captcha package in this tutorial. To install above package run below command in your terminal.
composer require mews/captcha
After installed this package, we need to configure this package in our providers array and alias array in config/app.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
'providers' => [
'aliases' => [
'Captcha' => Mews\Captcha\Facades\Captcha::class,
Now we need to create our controller which is going to hold our functions related to captcha. To create controller run below command in your terminal.
php artisan make:controller CaptchaController
After that paste below code in newly created CaptchaController.php
Navigate to routes/web.php and paste below code in it.
1 2 3 4 5 6 7 8
use Illuminate\Support\Facades\Route; use App\Http\Controllers\CaptchaController; Route::get('/', [CaptchaController::class, 'index'])->name('get.captcha'); Route::post('/my-captcha', [CaptchaController::class, 'submitCaptcha'])->name('submit.captcha'); Route::get('/refresh_captcha', [CaptchaController::class, 'refreshCaptcha'])->name('refresh.captcha');
Now we have finished with our configuration part. To get location information, run below command in your terminal:
php artisan serve
After that visit http://127.0.0.1:8000/
In this tutorial, we implemented intergrade captcha with our Laravel application. If you have any issue regarding this tutorial, mention your issue in comment section or reach me through my E-mail.You can obtain complete source code for this tutorial from this GitHub repository.