A small package that will allow you to use Yandex SmartCaptcha in your Laravel app
- Easy to use Yandex SmartCaptcha Blade component
- Easy to use Yandex SmartCaptcha validation
Install dsoloview/laravel-yandex-captcha from composer
composer require dsoloview/laravel-yandex-captcha
-
Add to your .env
YANDEX_CAPTCHA_CLIENT_KEY
YANDEX_CAPTCHA_SERVER_KEY
-
Publish config
php artisan vendor:publish --tag=yandex-captcha-config
- Add the Blade component to the form that needs a captcha
<form action="{{route('login')}}" method="post">
@csrf
<input type="text" name="email">
<input type="password" name="password">
<x-yandex-captcha></x-yandex-captcha>
<button type="submit">Send</button>
</form>
- Add YandexCaptcha validation rule
<?php
namespace App\Http\Requests;
use Dsoloview\YandexCaptcha\Rules\YandexCaptcha;
use Illuminate\Foundation\Http\FormRequest;
class LoginRequest extends FormRequest
{
public function rules(): array
{
return [
'email' => ['required', 'email'],
'password' => ['required', 'string', 'min:8'],
'smart-token' => ['required', new YandexCaptcha]
];
}
public function authorize(): bool
{
return true;
}
}
If you want to customize blade component you can publish it with
php artisan vendor:publish --tag=yandex-captcha-view