felipetti / captcha
This package is for integrating captcha service to Laravel project
Installs: 1 034
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- laravel/framework: ^10|^11|^12
README
What it does:
This package allows you to integrate Captcha V2 or V3 to your Laravel application.
Installation:
composer require felipetti/captcha
Usage instructions:
First you publish config file:
php artisan vendor:publish --tag=captcha
Config file named captcha.php is published in config folder of root directory. Open the file and put the secret key provided by Google inside "secret_key" field.
/* |-------------------------------------------------------------------------- | Secret Key |-------------------------------------------------------------------------- | | This is the Captcha key that only back-end has. | */ 'secret_key' => ''
There are three ways of captcha service integration, assuming $captcha is the field where front-end sends captcha response:
Form request:
use Felipetti\Captcha\Rule\CaptchaVerification; public function rules() { $captcha = ['required', 'string', new CaptchaVerification]; return compact('captcha'); }
Request validation:
Let's suppose we have a captcha controller, and we want to make validation inside:
use Felipetti\Captcha\Rule\CaptchaVerification; use Illuminate\Http\Request; class CaptchaController extends Controller { public function __invoke(Request $request) { $request->validate( ['captcha' => [new CaptchaVerification]] ); //... } }
Validator:
use Felipetti\Captcha\Rule\CaptchaVerification; use Illuminate\Support\Facades\Validator; use Illuminate\Http\Request; class CaptchaController extends Controller { public function __invoke(Request $request) { $rules = ['captcha' => [new CaptchaVerification]]; Validator::make($request->only('captcha'), $rules)->validate(); //... } }
Config:
Explanations in config file are quite expressive, so if you have any questions, please email guill388@hotmail.com.
Comments:
Please star me if you liked the package, it will really help me a lot.
Security:
If you discover any security-related issues, please e-mail me to the one above instead of using the issue tracker.
License:
The MIT License (MIT).