判断是否是ajax请求
方法1
if ($request->header('X-Requested-With') == 'XMLHttpRequest') { // ajax请求
方法2
if(Request->ajax()){
echo "AJAX";
}else{
echo '普通请求';
}
判断是否是api请求
判断形如是否是
https://www.xxx.com/api/user
//判断是否是api请求
if($request->is('api/*')){
return response()->json(['status' => 1000, 'msg' => '错误'], 400);
}else{//普通请求
return parent::render($request, $exception);
}