mlk9 / captcha-laravel
image captcha for Laravel 9+
v3.1.1
2023-12-25 05:55 UTC
Requires
- php: >=7.4
- ext-gd: *
- ext-mbstring: *
- illuminate/support: ~6|~7|~8|~9|~10
- intervention/image: ^3.1
Requires (Dev)
- laravel/pint: ^1.13.6
- orchestra/testbench: ^8.18
- phpstan/phpstan: ^1.10.47
- phpunit/phpunit: ^10.5
- symfony/var-dumper: ^6.4.0|^7.0.1
README
image captcha for Laravel
- works with session
- generates image your custom
Persian Docs for V2 : https://vrgl.ir/WQXCT
Installation
you can install this package via composer
composer require mlk9/captcha-laravel
then publish vendor
php artisan vendor:publish --tag=captcha-laravel
Documents
Configure
- type (array , [char, math])
- backgrounds (array)
- char (string)
- length (int)
- font (string|array)
- colors (array)
- width (int)
- height (int)
- type_hash ([laravel, sha256, md5])
Generate captcha simple
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>
Validation
You can use captcha
rule in your validations
Illuminate\Support\Facades\Validator::validate($request->all(), ["captchaField"=>"captcha"] );
also
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'); }
notice for v2
if you get error for font you can replace in config
'font' => public_path('vendor/captcha/fonts/tahoma.ttf'),