Skip to main content

Usage

The Laravel Captcha implementation involves two main components - rendering the captcha and executing validation.

Render the Captcha

In order to integrate the Captcha into your form, you should include it within the head and body tags like so:

<head>
<x-captcha-js />
</head>
<body>
<form action="" method="post">
...
<x-captcha-container />
</form>
</body>

Validate the Captcha

The response from the Captcha service will require validation. This can be achieved by using Laravel's Validator facade as follows:

use Rahul900day\Captcha\Facades\Captcha;
use Rahul900day\Captcha\Rules\Captcha as CaptchaRule;
use Illuminate\Support\Facades\Validator;

Validator::make($request, [
Captcha::getResponseName() => [
'required',
new CaptchaRule(),
],
]);

In the above code, Captcha::getResponseName() retrieves the name of the response variable, which should be marked as 'required' and should adhere to the rule defined by new CaptchaRule().