Using verification code in Laravel

不言
Release: 2023-03-25 15:28:02
Original
2501 people have browsed it

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"}
Copy after login

or

composer require mews/captcha
Copy after login

Then run the following command to update the library dependencies

composer update
Copy after login

or

 composer install
Copy after login

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',
]
Copy after login

for Laravel 5.1

'providers' => [
    // ...
    Mews\Captcha\CaptchaServiceProvider::class,
]
Copy after login

Find the aliases key in config/app.php.

'aliases' => [
     // ...
    'Captcha' => 'Mews\Captcha\Facades\Captcha',
]
Copy after login

for Laravel 5.1

 'aliases' => [
        // ...
        'Captcha' => Mews\Captcha\Facades\Captcha::class,
    ]
Copy after login

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,
    ],    // ...];
Copy after login

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>
Copy after login
             

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template