Home > PHP Framework > Laravel > body text

How to install verification code package in laravel

藏色散人
Release: 2021-12-22 11:45:56
Original
2465 people have browsed it

How to install the verification code package in laravel: 1. Log in to the website packagist.org; 2. Search for laravel captcha and find "mews/captcha"; 3. Install the verification code according to the usage method on packagist. .

How to install verification code package in laravel

The operating environment of this article: Windows 7 system, Laravel version 5.7, DELL G3 computer.

How to install the verification code package in laravel?

Laravel - Captcha

  • # I feel that I use better verification code bags, take it out to share, fool -style tutorial, big guy don't spray. :smile: :smile: :smile:
  • Installation steps:
    • First, log in to the website packagist.org and find laravel captcha, find mews/captcha , and install the verification code step by step according to the usage method on packagist.
    • composer installation: composer require mews/captcha
    • Registrationproviders (config/app .php) , append the following code at the end of this array:
      Mews\Captcha\CaptchaServiceProvider::class,
    • Register aliases (config/app.php), and append the following code to the end of this array:
      'Captcha' => Mews\Captcha \Facades\Captcha::class,
    • Generate the configuration file and enter the following command in the Composer command line:
      php artisan vendor:publish
    • Enter the config/captcha.php file and modify the default array to style the verification code , modifications in quantity and size.
      'default'   => [
      'length'    => 5,
      'width'     => 100,
      'height'    => 34,
      'quality'   => 90,
      ],
      Copy after login
  • Used in the page:
<div class="row">
    <div class="col-md-8">
        <input type="text" class="form-control {{$errors->has(&#39;captcha&#39;)?&#39;parsley-error&#39;:&#39;&#39;}}" name="captcha" placeholder="captcha">
    </div>
    <div class="col-md-4">
        <img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src=&#39;{{captcha_src()}}&#39;+Math.random()">
    </div>
    @if($errors->has(&#39;captcha&#39;))
        <div class="col-md-12">
            <p class="text-danger text-left"><strong>{{$errors->first(&#39;captcha&#39;)}}</strong></p>
        </div>
    @endif
</div>
Copy after login
  • Click the image to refresh, the following code:
<img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src=&#39;{{captcha_src()}}&#39;+Math.random()">
Copy after login
  • Rewrite the AuthController login verification method and customize the prompt message:

    • First introduce the following code:
      use Illuminate\Http\Request;

    • Rewrite the validateLogin method:

 protected function validateLogin(Request $request){
        $this->validate($request, [
            $this->loginUsername() => &#39;required&#39;,
            &#39;password&#39; => &#39;required&#39;,
            &#39;captcha&#39; => &#39;required|captcha&#39;,
        ],[
            &#39;captcha.required&#39; => trans(&#39;validation.required&#39;),
            &#39;captcha.captcha&#39; => trans(&#39;validation.captcha&#39;),
        ]);
    }
Copy after login
  • Downloading and switching of font libraries:
    • First you need to download the font library
    • After the download is completed, copy the src/zh-CN folder in the compressed package to the resources/lang folder in the project directory.
    • Modify the config->app.php file and modify the code as follows:
      &#39;locale&#39; => &#39;zh-CN&#39;,
      Copy after login
  • Since captcha does not have a Chinese explanation in the Chinese package, you need to manually add a Chinese explanation. The specific operations are as follows:
    • Open resources/zh-CN/validation.php, append the following key-value pairs to the total array:
      &#39;captcha&#39;                  => &#39;:attribute 不正确。&#39;,
      Copy after login
    • In attributes Append the following key-value pairs to the array:
      &#39;captcha&#39;               => &#39;验证码&#39;,
      Copy after login
      Related recommendations: The latest five Laravel video tutorials                                      

      The above is the detailed content of How to install verification code package 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