A simple Laravel 4 service provider for including the Captcha for Laravel 4.
This library is not maintained for 3rd party use.
composer require latrell/captcha dev-master
To use the Captcha Service Provider, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this.
Find the providers
key in app/config/app.php
and register the Captcha Service Provider.
'providers' => array(
// ...
'Latrell\Captcha\CaptchaServiceProvider',
)
Find the aliases
key in app/config/app.php
.
'aliases' => array(
// ...
'Captcha' => 'Latrell\Captcha\Facades\Captcha',
)
Then publish the config file with php artisan config:publish latrell/captcha
. This will add the file app/config/packages/latrell/captcha/config.php
.
This config file is the primary way you interact with Captcha.
// [your site path]/app/routes.php
Route::any('/captcha-test', function()
{
if (Request::getMethod() == 'POST')
{
$rules = array('captcha' => array('required', 'captcha'));
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
echo '<p style="color: #ff0000;">Incorrect!</p>';
}
else
{
echo '<p style="color: #00ff30;">Matched :)</p>';
}
}
$content = Form::open(array(URL::to(Request::segment(1))));
$content .= '<p>' . HTML::image(Captcha::url()) . '</p>';
$content .= '<p>' . Form::text('captcha') . '</p>';
$content .= '<p>' . Form::submit('Check') . '</p>';
$content .= '<p>' . Form::close() . '</p>';
return $content;
});