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. .
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
laravel captcha
, find mews/captcha
, and install the verification code step by step according to the usage method on packagist.
composer require mews/captcha
providers (config/app .php)
, append the following code at the end of this array: Mews\Captcha\CaptchaServiceProvider::class,
aliases (config/app.php)
, and append the following code to the end of this array: 'Captcha' => Mews\Captcha \Facades\Captcha::class,
php artisan vendor:publish
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, ],
<div class="row"> <div class="col-md-8"> <input type="text" class="form-control {{$errors->has('captcha')?'parsley-error':''}}" name="captcha" placeholder="captcha"> </div> <div class="col-md-4"> <img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src='{{captcha_src()}}'+Math.random()"> </div> @if($errors->has('captcha')) <div class="col-md-12"> <p class="text-danger text-left"><strong>{{$errors->first('captcha')}}</strong></p> </div> @endif </div>
<img src="{{captcha_src()}}" style="cursor: pointer" onclick="this.src='{{captcha_src()}}'+Math.random()">
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() => 'required', 'password' => 'required', 'captcha' => 'required|captcha', ],[ 'captcha.required' => trans('validation.required'), 'captcha.captcha' => trans('validation.captcha'), ]); }
resources/lang
folder in the project directory. config->app.php
file and modify the code as follows: 'locale' => 'zh-CN',
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: resources/zh-CN/validation.php
, append the following key-value pairs to the total array: 'captcha' => ':attribute 不正确。',
'captcha' => '验证码',
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!