canducci / recaptcha
Canducci Recaptcha
Requires
- php: >=5.3.0
- laravel/framework: 5.1.*|5.0.*
Requires (Dev)
- phpspec/phpspec: ~2.1
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-11-29 04:51:19 UTC
README
CANDUCCI RECAPTCHA
Quick start
Required setup
In the require
key of composer.json
file add the following
"canducci/recaptcha": "1.0.*"
Run the Composer update comand
$ composer update
In your config/app.php
add providers
array
'providers' => array( ..., Canducci\ReCaptcha\Providers\ReCaptchaServiceProvider::class, ),
At the end of config/app.php
add o aliases
(Facade) in array
'aliases' => array( ..., 'ReCaptcha' => Canducci\ReCaptcha\Facades\ReCaptcha::class, ),
Run the Artisan comand
php artisan vendor:publish --force --provider="Canducci\ReCaptcha\Providers\ReCaptchaServiceProvider"
In the config/recaptcha.php
add site_key
e secret_key
of Google ReCaptcha (https://www.google.com/recaptcha/intro/index.html).
###Usage
Blade in View
The @recaptchascript()
blade in the tag <head></head>
, example:
<!DOCTYPE html> <html> <head> <tile>ReCaptcha Test</tile> @recaptchascript() </head>
The @recaptcha()
blade in the tag <form></form>
, example:
<form action="/v" method="post"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> @recaptcha() <button type="submit">Send</button> </form>
Variable in View
Controller
public function index1() { return view('index1') ->with('script', recaptcha_script()) ->with('captcha', recaptcha_render()); }
Html
<!DOCTYPE html> <html> <head> <tile>ReCaptcha Test</tile> {!! $script !!}
and
<form action="/v" method="post"> <input type="hidden" name="_token" value="{{ csrf_token() }}"> {!! $captcha !!} <button type="submit">Send</button> </form>
Verify g-recaptcha-response
is valid?
Use namespace:
use App\Http\Requests\ReCaptchaRequest;
use Canducci\ReCaptcha\ReCaptcha;
- With
ReCaptchaRequest
, example:
public function post(ReCaptchaRequest $request, ReCaptcha $re) { }
- In the method, example:
public function v(Request $request, ReCaptcha $re) { $valid = $re->valid($request->get('g-recaptcha-response')); if ( $valid->success() ) { //success } else { //not valid var_dump( $valid->errors() ); } }
###The settings of the tags can be like this:
- Function:
$script = recaptcha_script(Canducci\ReCaptcha\ReCaptchaScriptRender::Onload, Canducci\ReCaptcha\ReCaptchaScriptLanguage::Armenian, 'function_CallBack'); $render = recaptcha_render(Canducci\ReCaptcha\ReCaptchaRenderTheme::Ligth, Canducci\ReCaptcha\ReCaptchaRenderDataType::Image, Canducci\ReCaptcha\ReCaptchaRenderDataSize::Normal, 0, 'function_CallBack', 'function_dataExpiredCallBack');
- Facade:
use `Canducci\ReCaptcha\Facades\ReCaptcha as ReCaptchaFacade`
$script = ReCaptchaFacade::script(Canducci\ReCaptcha\ReCaptchaScriptRender::Onload, Canducci\ReCaptcha\ReCaptchaScriptLanguage::Armenian, 'function_CallBack'); $render = ReCaptchaFacade::render(Canducci\ReCaptcha\ReCaptchaRenderTheme::Ligth, Canducci\ReCaptcha\ReCaptchaRenderDataType::Image, Canducci\ReCaptcha\ReCaptchaRenderDataSize::Normal, 0, 'function_CallBack', 'function_dataExpiredCallBack');
- Blade:
@recaptchascript(Canducci\ReCaptcha\ReCaptchaScriptRender::Onload, Canducci\ReCaptcha\ReCaptchaScriptLanguage::Armenian, 'function_CallBack') @recaptcha(Canducci\ReCaptcha\ReCaptchaRenderTheme::Ligth, Canducci\ReCaptcha\ReCaptchaRenderDataType::Image, Canducci\ReCaptcha\ReCaptchaRenderDataSize::Normal, 0, 'function_CallBack', 'function_dataExpiredCallBack')
Obs: These settings are not compulsory, but if necessary, following Google's website tutorial can be made.