Home  >  Article  >  Backend Development  >  Using verification code in Laravel

Using verification code in Laravel

不言
不言Original
2018-05-08 10:10:452502browse

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

Using verification code in Laravel

Using verification code in Laravel

Installation

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.iniEnable GD2 DLL expansionphp_gd2.dll, and also must open php_fileinfo.dll and php_mbstring.dll

to use

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,
    ]

Configuration

You can customize the style of the verification code and the number of input characters

Copy the configuration file to configUnder 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(&#39;captcha&#39;) ? &#39; has-error&#39; : &#39;&#39; }}">
    <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(&#39;flat&#39;) }}" onclick="this.src=&#39;/captcha/flat?&#39;+Math.random()" title="点击图片重新获取验证码" alt="Using verification code in Laravel" >

        @if ($errors->has(&#39;captcha&#39;))            <span class="help-block">
            <strong>{{ $errors->first(&#39;captcha&#39;) }}</strong>
        </span>
        @endif    </p></p>

             

Related recommendations:

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn