From c229828ab0528827af84ca834021fa93f965585a Mon Sep 17 00:00:00 2001 From: ccdream Date: Mon, 19 Aug 2024 15:58:33 +0800 Subject: [PATCH] Update HasPermissions.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $this->getKeyName()是 admin_users表的主键,如果自定义登录后,主键名不为id时, 权限会出错. 这里直接取 admin_permissions 表的组件. --- src/Traits/HasPermissions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Traits/HasPermissions.php b/src/Traits/HasPermissions.php index 573ac4ae3..bf0672dc7 100644 --- a/src/Traits/HasPermissions.php +++ b/src/Traits/HasPermissions.php @@ -21,11 +21,14 @@ public function allPermissions(): Collection return $this->allPermissions; } + $permissionsModel = config('admin.database.permissions_model'); + $primaryKey = (new $permissionsModel)->getKeyName(); + return $this->allPermissions = $this->roles ->pluck('permissions') ->flatten() - ->keyBy($this->getKeyName()); + ->keyBy($primaryKey); } /**