Home > Article > Backend Development > Using verification code in Laravel
This article mainly introduces the use of verification codes in Laravel, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
Add a reference to the verification code in composer.json
{ "require": { "laravel/framework": "5.0.*", "mews/captcha": "~2.0" }, "minimum-stability": "dev"}
or
composer require mews/captcha
Then run the following command to update the library dependencies
composer update
or
composer install
In Windows system, it must be in
php.ini
Enable GD2 DLL expansionphp_gd2.dll
, and also must openphp_fileinfo.dll
andphp_mbstring.dll
Inject the verification code service provider in config/app.php
.
'providers' => [ // ... 'Mews\Captcha\CaptchaServiceProvider', ]
for Laravel 5.1
'providers' => [ // ... Mews\Captcha\CaptchaServiceProvider::class, ]
Find the aliases key
in config/app.php
.
'aliases' => [ // ... 'Captcha' => 'Mews\Captcha\Facades\Captcha', ]
for Laravel 5.1
'aliases' => [ // ... 'Captcha' => Mews\Captcha\Facades\Captcha::class, ]
You can customize the style of the verification code and the number of input characters
Copy the configuration file to config
Under the directory $ php artisan vendor:publish
##Configuration file path
config/ captcha.php
return [ 'default' => [ 'length' => 5, 'width' => 120, 'height' => 36, 'quality' => 90, ], // ...];Specific usage examples
<p class="form-group {{ $errors->has('captcha') ? ' has-error' : '' }}"> <label for="captcha" class="col-md-4 control-label">验证码</label> <p class="col-md-6"> <input id="captcha" class="form-control" name="captcha" > <img class="thumbnail captcha" src="{{ captcha_src('flat') }}" onclick="this.src='/captcha/flat?'+Math.random()" title="点击图片重新获取验证码" alt="Using verification code in Laravel" > @if ($errors->has('captcha')) <span class="help-block"> <strong>{{ $errors->first('captcha') }}</strong> </span> @endif </p></p>
Laravel's template yeild usage
laravel framework about the implementation of search function
Laravel deployment under CentOS7 and forwarding with nginx
The above is the detailed content of Using verification code in Laravel. For more information, please follow other related articles on the PHP Chinese website!