DEV Community

Cover image for Add Captcha On Laravel Forms
Arman Rahman
Arman Rahman

Posted on

7

Add Captcha On Laravel Forms

To add Captcha to Laravel form without any API Connection

Image description

Install mews/captcha



composer require mews/captcha


Enter fullscreen mode Exit fullscreen mode

Find the providers key in config/app.php and register the Captcha Service Provider. for for Laravel 5.1+



'providers' => [
        // ...
        Mews\Captcha\CaptchaServiceProvider::class,
    ]


Enter fullscreen mode Exit fullscreen mode

Find the aliases key in config/app.php.



'aliases' => [
        // ...
        'Captcha' => Mews\Captcha\Facades\Captcha::class,
    ]


Enter fullscreen mode Exit fullscreen mode

publish mews/captcha by running -



$ php artisan vendor:publish


Enter fullscreen mode Exit fullscreen mode

Add this to .env to disable captcha



CAPTCHA_DISABLE=true


Enter fullscreen mode Exit fullscreen mode

Add this on laravel blade



 //register.blade.php
    <img src="{{ captcha_src() }}" alt="captcha">
        <div class="mt-2"></div>
        <input 
            type="text" name="captcha" class="form-control @error('captcha') is-invalid @enderror" placeholder="Please Insert Captch"
            >
         @error('captcha') 
         <div class="invalid-feedback">{{ $message }}</div> @enderror 


Enter fullscreen mode Exit fullscreen mode

in controller validate like this -



$request->validate([
'captcha' => 'required|captcha'
],[],[
     'captcha.required' => 'Captcha is required',
     'captcha.captcha' => 'Captcha is invalid',
])


Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more