diff --git a/app/Http/Middleware/ParamsValidation.php b/app/Http/Middleware/ParamsValidation.php index 2e574879ae6122c4b6abcec858e3eaff42834f4a..7927928e16a36ae131e375bdfe7c103aff7058ef 100644 --- a/app/Http/Middleware/ParamsValidation.php +++ b/app/Http/Middleware/ParamsValidation.php @@ -32,6 +32,37 @@ class ParamsValidation if (!class_exists($RulesClass)) { throw new DevException(); } + + $path = $request->path(); + + // 处理参数在路由上面的 + $rRoute = $request->route(); + if( isset($rRoute[2]) && count($rRoute[2])>0 ) + { + $RouteList = Utils::getRouteList(); + $parasKey = $rRoute[2]; + $path = array_filter($RouteList, function($v) use ($parasKey, $path) { + $vv = $v; + foreach( $parasKey as $pk=>$pv ) + { + if( strpos($v, $pk) === false ) return false; + + $vv = str_replace("{".$pk."}", $pv, $vv); + } + + if( substr($vv, 0,1)==='/' ) $vv = substr($vv, 1); + if( $vv != $path ) return false; + + return true; + }); + + + if( count($path)>1 ) throw new DevException(); + + $path = current($path); + if( substr($path, 0,1)==='/' ) $path = substr($path, 1); + } + $rules = new $RulesClass($request->route()->uri, $request); HandleValidator::execute($request->input(), $rules);