From 8bb69d6d67387f7a00d93a2f5fab98860f06e704 Mon Sep 17 00:00:00 2001 From: erikn69 Date: Fri, 8 Nov 2024 13:45:41 -0500 Subject: [PATCH] Fix: #2749 bug "Can no longer delete permissions" (#2759) * Fix: #2749 bug * Test added --- src/PermissionRegistrar.php | 4 ++-- tests/PermissionTest.php | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/PermissionRegistrar.php b/src/PermissionRegistrar.php index 643ed92ea..cc2e1ca5f 100644 --- a/src/PermissionRegistrar.php +++ b/src/PermissionRegistrar.php @@ -349,7 +349,7 @@ private function getSerializedRoleRelation($permission): array private function getHydratedPermissionCollection(): Collection { - $permissionInstance = new ($this->getPermissionClass())(); + $permissionInstance = (new ($this->getPermissionClass())())->newInstance([], true); return Collection::make(array_map( fn ($item) => (clone $permissionInstance) @@ -368,7 +368,7 @@ private function getHydratedRoleCollection(array $roles): Collection private function hydrateRolesCache(): void { - $roleInstance = new ($this->getRoleClass())(); + $roleInstance = (new ($this->getRoleClass())())->newInstance([], true); array_map(function ($item) use ($roleInstance) { $role = (clone $roleInstance) diff --git a/tests/PermissionTest.php b/tests/PermissionTest.php index b23094544..d43645730 100644 --- a/tests/PermissionTest.php +++ b/tests/PermissionTest.php @@ -67,4 +67,15 @@ public function it_is_retrievable_by_id() $this->assertEquals($this->testUserPermission->id, $permission_by_id->id); } + + /** @test */ + public function it_can_delete_hydrated_permissions() + { + $this->reloadPermissions(); + + $permission = app(Permission::class)->findByName($this->testUserPermission->name); + $permission->delete(); + + $this->assertCount(0, app(Permission::class)->where($this->testUserPermission->getKeyName(), $this->testUserPermission->getKey())->get()); + } }