1.我们在项目的根目录可以找到composer.json这个文件,加上下边的代码

    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "gregwar/captcha": "1.*"
    },

2.进入项目根目录进行composer update 

laravel怎么加入验证码功能

3.设置路由

// 验证码的路由
Route::get('captcha','Index\[email protected]');

4.输出验证码

/*
author:咔咔
address:陕西西安
wechat:fangkangfk
*/

// 验证码
    public function code()
    {
        $builder = new CaptchaBuilder();

        $builder->build(150,32);

        $phrase = $builder->getPhrase();

        //把内容存入session

        Session::flash('milkcaptcha', $phrase); //存储验证码

        ob_clean();

        return response($builder->output())->header('Content-type','image/jpeg');
    }

5.在页面输出验证码

<img src="{{url('captcha')}}" style="width: 130px;height: 60px;margin-left: 410px;position: relative;top: -74px;" onclick="this.src=this.src+'?'+Math.random()" class="code" >

6.点击验证码进行刷新,就是onclick事件

 

laravel怎么加入验证码功能

相关文章: