Laravel Package for the ArCaptcha
This package supports PHP 7.3+
.
For PHP integration you can use mohammadv184/arcaptcha package.
You can install the package via composer:
composer require mohammadv184/arcaptcha-laravel
Laravel 5.5 (or greater) uses package auto-discovery, so doesn't require you to manually add the Service Provider, but if you don't use auto-discovery ArCaptchaServiceProvider must be registered in config/app.php:
'providers' => [
...
Mohammadv184\ArCaptcha\Laravel\ArCaptchaServiceProvider::class,
];
You can use the facade for shorter code. Add ArCaptcha to your aliases:
'aliases' => [
...
'ArCaptcha' => Mohammadv184\ArCaptcha\Laravel\Facade\ArCaptcha::class,
];
Create config/arcaptcha.php configuration file using the following artisan command:
php artisan vendor:publish --provider="Mohammadv184\ArCaptcha\Laravel\ArCaptchaServiceProvider"
Open .env file and set ARCAPTCHA_SITE_KEY
and ARCAPTCHA_SECRET_KEY
:
# in your .env file
ARCAPTCHA_SITE_KEY=YOUR_API_SITE_KEY
ARCAPTCHA_SECRET_KEY=YOUR_API_SECRET_KEY
Before starting please add the validation message to resources/lang/[LANG]/validation.php
file
return [
...
'arcaptcha' => 'Hey!!! :attribute is wrong!',
];
How to use ArCaptcha in Laravel.
Insert @arcaptchaScript
blade directive before closing </head>
tag.
You can also use ArCaptcha::getScript()
.
<!DOCTYPE html>
<html>
<head>
...
@arcaptchaScript
</head>
After you have to insert @arcaptchaWidget
blade directive inside the form where you want to use the field arcaptcha-token
.
You can also use ArCaptcha::getWidget()
.
<form>
@csrf
...
@arcaptchaWidget
<!-- OR -->
{!! ArCaptcha::getWidget() !!}
<input type="submit">
</form>
Add arcaptcha
to your rules
$validator = Validator::make(request()->all(), [
...
'arcaptcha-token' => 'arcaptcha',
]);
// check if validator fails
if($validator->fails()) {
...
$errors = $validator->errors();
}
The MIT License (MIT). Please see License File for more information.