From d1f72225a55e12252c5748e18f3a2e52ccadbbe4 Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 5 Dec 2024 20:33:02 +0800 Subject: [PATCH 1/2] fix: lazy loading issue with permissions --- src/Traits/InteractsWithPermission.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Traits/InteractsWithPermission.php b/src/Traits/InteractsWithPermission.php index c3856ba..d9ceb58 100644 --- a/src/Traits/InteractsWithPermission.php +++ b/src/Traits/InteractsWithPermission.php @@ -173,6 +173,10 @@ public function revokeAllPermissions(): int */ public function getPermissions(): array { + if (! $this->relationLoaded('permissions')) { + $this->load('permissions'); + } + return $this->permissions->pluck('slug')->toArray(); } } From f75f0dd2a713deea19c54b4a07010bb63ef4763e Mon Sep 17 00:00:00 2001 From: Arjay Angeles Date: Thu, 5 Dec 2024 20:35:29 +0800 Subject: [PATCH 2/2] refactor: use loadMissing --- src/Traits/InteractsWithPermission.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Traits/InteractsWithPermission.php b/src/Traits/InteractsWithPermission.php index d9ceb58..a3fab75 100644 --- a/src/Traits/InteractsWithPermission.php +++ b/src/Traits/InteractsWithPermission.php @@ -173,9 +173,7 @@ public function revokeAllPermissions(): int */ public function getPermissions(): array { - if (! $this->relationLoaded('permissions')) { - $this->load('permissions'); - } + $this->loadMissing('permissions'); return $this->permissions->pluck('slug')->toArray(); }