1.下载laravel扩展包
https://packagist.org
gregwar/captcha
composer require gregwar/captcha
2.验证生成
public function captcha($tmp){
$builder = new CaptchaBuilder;
$builder->build();
Session::put('imgcode',strtoupper($builder->getPhrase()));
header('Content-type: image/jpeg');
$builder->output();
}
3.路由指引
Route::get('captcha/{tmp}', 'spicyController@captcha');
4.前端显示
<div class="col-md-4">
<input id="imgcode" type="text" class="form-control" placeholder="验证码" name="imgcode">
@if($errors->has('imgcode'))
<p style="color:red">{{$errors->first('imgcode')}}</p>
@endif
</div>
<button class="btn btn-default" style=" padding: 0px 0px;">
<img src="{{url('/captcha/1')}}" alt="" onclick="this.src='{{url('/captcha')}}/'+Math.random()" width="80" height="34" border="0">
</button>
</div>