第一步:使用Composer
安装think-captcha
扩展包
composer require topthink/think-captcha
第二步: 设置路由
Route::get('captcha/:id','\\think\\captcha\\CaptchaController@index');
Route::get('captcha','Captcha/captcha');
第三步:控制器创建方法
public function captcha(Request $request)
{
$id = mt_rand(100000, 999999);
$uniqid = uniqid("$id");
//返回数据 验证码图片路径、验证码标识
$data = [
'src' => $request->domain().captcha_src($uniqid),
'uniqid' => $uniqid
];
return json(['code'=>200,'msg'=>'success','data'=>$data]);
}