From 64f1d000b86e6988352caf471a753fdb49038d80 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Tue, 9 Aug 2022 16:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=9D=83=E9=99=90=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/Middleware/Permission.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 */