• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Laravel中使用验证码

php 搞代码 3年前 (2022-01-22) 70次浏览 已收录 0个评论
文章目录[隐藏]

这篇文章主要介绍了关于Laravel中使用验证码,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

预览

安装

composer.json中添加验证码的引用

{    "require": {        "laravel/framework": "5.0.*",        "mews/captcha": "~2.0"    },    "minimum-stability": "dev"}

或者是

composer require mews/captcha

接着就是运行下面的命令来更新库的依赖

composer update

或者

 composer install

在windows系统中,必须在php.ini开启GD2 DLL拓展 php_gd2.dll,同时还必须开启php_fileinfo.dllphp_mbstring.dll

使用

~来1源gaodai#ma#com搞*代#码1网搞代gaodaima码config/app.php 中注入验证码服务提供者。

'providers' => [    // ...    'Mews\Captcha\CaptchaServiceProvider',]

for Laravel 5.1+

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

找到aliases keyconfig/app.php

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

for Laravel 5.1+

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

配置

可以自定义验证码的样式以及输入字符的数量

将配置文件拷贝到config目录下
$ php artisan vendor:publish

配置文件路径
config/captcha.php

return [    'default'   => [        'length'    => 5,         'width'     => 120,         'height'    => 36,         'quality'   => 90,    ],    // ...];

具体的使用例子

 <p class="form-group {{ $errors->has('captcha') ? ' has-error' : '' }}">    <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('flat') }}" onclick="this.src='/captcha/flat?'+Math.random()" title="点击图片重新获取验证码">        @if ($errors->has('captcha'))            <span class="help-block">            <strong>{{ $errors->first('captcha') }}</strong>        </span>        @endif    </p></p>

相关推荐:

laravel的模板yeild使用

laravel框架关于搜索功能的实现

CentOS7下Laravel部署并用nginx转发

以上就是Laravel中使用验证码的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Laravel中使用验证码

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址