1、创建独立验证器
2、创建中间件
php think make:middleware Check
3、在中间件中判断验证器内容
public function handle($request, \Closure $next)
{
//取值
$data =$request->param();
try {
validate(Error::class)->batch(true)->check($data);
return $next($request);
}catch (ValidateException $exception){
$error = $exception->getError();
return fail(2001,$error, $data );
}
}
4、路由中调用中间件
Route::post('save','Order/save')->middleware(\app\api\middleware\Check::class);