image captcha for Laravel
- works with session
- generates image your custom
Persian Docs for V2 : https://vrgl.ir/WQXCT
you can install this package via composer
composer require mlk9/captcha-laravel
then publish vendor
php artisan vendor:publish --tag=captcha-laravel
- type (array , [char, math])
- backgrounds (array)
- char (string)
- length (int)
- font (string|array)
- colors (array)
- width (int)
- height (int)
- type_hash ([laravel, sha256, md5])
you can use component:
<x-captcha-box />
<x-captcha-box-refresh /> //via refresh
or create custom like this:
<div>
<div>
<div>
<!-- Captcha generate -->
<img src="{{ \Mlk9\Captcha\Facades\Captcha::generate()->image }}" alt="captha">
</div>
<div>
<div>{{ __('captcha.captcha') }}</div>
<input id="captcha" name="captcha" type="text" required autocomplete="off">
</div>
</div>
</div>
You can use captcha
rule in your validations
Illuminate\Support\Facades\Validator::validate($request->all(),
["captchaField"=>"captcha"]
);
you can add middleware captcha
to your routes or controllers
and the third way use isValid(string: entry)
from \Mlk9\Captcha\Facades\Captcha::class
for example :
if(!\Mlk9\Captcha\Facades\Captcha::isValid($request->captcha))
{
return back()->withErrors('Wrong Captcha');
}
if you get error for font you can replace in config
'font' => public_path('vendor/captcha/fonts/tahoma.ttf'),