diff --git a/src/Http/Middleware/Permission.php b/src/Http/Middleware/Permission.php index 413d44b..0585f33 100644 --- a/src/Http/Middleware/Permission.php +++ b/src/Http/Middleware/Permission.php @@ -28,13 +28,26 @@ class Permission { $user = Admin::user(); + $routeName = $request->route()->getName(); + $ability = $routeName; + + foreach ([ + 'store' => 'create', + 'update' => 'edit', + ] as $k => $v) { + if (preg_match("/(.*\.){$k}$/", $routeName, $matches)) { + $ability = $matches[1].$v; + break; + } + } + if ( ! $user || ! empty($args) || ! config('admin.permission.enable') || $this->shouldPassThrough($request) || $user->isAdministrator() - || $this->checkRoutePermission($request) + || $user->hasPermission($ability) ) { return $next($request); } @@ -51,7 +64,7 @@ class Permission /** * If the route of current request contains a middleware prefixed with 'admin.permission:', * then it has a manually set permission middleware, we need to handle it first. - * + * 已废弃 * @param Request $request * @return bool */