How to install the verification code package in laravel
Xiaobian shares with you how laravel installs the Captcha package. I believe most people still don't know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's find out together!
Laravel installation Captcha package method: 1. Login URL packagist.org;2. Find laravel captcha, find "mews/captcha";3. According to the use method on packagist to achieve the installation of Captcha.
Operating environment: Windows 7 system, Laravel 5.7 version, DELL G3 computer.
Laravel -Captcha (captcha)
I feel the use of a relatively good Captcha package, take it out to share, fool tutorial, big brother do not spray.: smile: :smile: :smile:
Installation steps:
First, log in to packagist.org to find laravel captcha, find mews/captcha, and install Captcha step by step according to the usage method on packagist.
composer install: composer require mews/captcha
Register providers (config/app.php) and append the following code to 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,
To generate the configuration file, enter the following command on the Composer command line:
php artisan vendor:publish
Enter config/captcha.php file, modify default array to modify style, quantity and size of Captcha.
'default' => ['length' => 5,'width' => 100,'height' => 34,'quality' => 90,],
Pages used:
Overwrite AuthController login authentication method and customize prompt information:
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'), ]); }
Download and switch font library:
First you need to download the font library
After downloading, copy the src/zh-CN folder in the archive to the resources/lang folder in the project directory.
Modify config-> app.php file as follows:
'locale' => 'zh-CN',
Since captcha has no Chinese explanation in the Chinese package, you need to add Chinese explanation manually. The specific operation is as follows:
Open resources/zh-CN/validation.php and append the following key pairs to the total array:
'captcha' => ':attribute is incorrect. ',
Append the following key-value pairs to the attributes array:
'captcha' => 'Captcha', above is "laravel how to install Captcha package" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!