laravel安裝驗(yàn)證碼包的方法:1、登錄網(wǎng)址packagist.org;2、查找laravel captcha,找到“mews/captcha”;3、根據(jù)packagist上的使用方法實(shí)現(xiàn)驗(yàn)證碼的安裝即可。
本文操作環(huán)境:windows7系統(tǒng)、Laravel5.7版,DELL G3電腦。
laravel怎么安裝驗(yàn)證碼包?
Laravel – 驗(yàn)證碼(captcha)
- 本人感覺(jué)用的比較好的驗(yàn)證碼包,拿出來(lái)分享一下,傻瓜式教程,大佬別噴。?? ?? ??
- 安裝步驟:
- 首先,登錄網(wǎng)址packagist.org查找 laravel captcha,找到mews/captcha ,根據(jù)packagist上的使用方法一步步來(lái)實(shí)現(xiàn)驗(yàn)證碼的安裝。
- composer安裝:composer require mews/captcha
- 注冊(cè)providers (config/app.php) ,在這個(gè)數(shù)組中的最后追加如下代碼:
MewsCaptchaCaptchaServiceProvider::class, - 注冊(cè)aliases (config/app.php),在這個(gè)數(shù)組中的最后追加如下代碼:
‘Captcha’ => MewsCaptchaFacadesCaptcha::class, - 生成配置文件,在Composer命令行中輸入如下命令:
php artisan vendor:publish - 進(jìn)入config/captcha.php 文件,修改default 數(shù)組 可以對(duì)驗(yàn)證碼進(jìn)行樣式、數(shù)量、大小上的修改。
'default' => [ 'length' => 5, 'width' => 100, 'height' => 34, 'quality' => 90, ],
- 頁(yè)面中使用:
<div> ????<div> ????????<input>has('captcha')?'parsley-error':''}}"?name="captcha"?placeholder="captcha"> ????</div> ????<div> ????????@@##@@ ????</div> ????@if($errors->has('captcha')) ????????<div> ????????????<p><strong>{{$errors->first('captcha')}}</strong></p> ????????</div> ????@endif </div>
- 點(diǎn)擊圖片刷新,如下代碼:
@@##@@
-
重寫AuthController 登錄驗(yàn)證方法,并自定義提示信息:
-
首先要引入如下代碼:
use IlluminatehttpRequest; -
重寫validateLogin方法:
-
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'), ]); }
- 字體庫(kù)的下載與切換:
- 首先需要下載字體庫(kù)
- 下載完成后,將壓縮包中 src/zh-CN 文件夾拷貝到項(xiàng)目目錄的 resources/lang 文件夾下。
- 修改 config->app.php 文件,修改代碼如下:
'locale' => 'zh-CN',
- 由于captcha在中文包中沒(méi)有中文解釋,所以需要手動(dòng)添加中文解釋,具體操作如下:
- 打開(kāi) resources/zh-CN/validation.php,在總數(shù)組中追加如下鍵值對(duì):
'captcha' => ':attribute 不正確。',
- 在 attributes ?數(shù)組中追加如下鍵值對(duì):
'captcha' => '驗(yàn)證碼',
- 打開(kāi) resources/zh-CN/validation.php,在總數(shù)組中追加如下鍵值對(duì):
相關(guān)推薦:最新的五個(gè)Laravel視頻教程? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END
喜歡就支持一下吧
相關(guān)推薦