diff --git a/CHANGELOG.md b/CHANGELOG.md index d50a3b35..094cdbc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to `laravel-permission` will be documented in this file +## 6.10.1 - 2024-11-08 + +### What's Changed + +* Fix #2749 regression bug in `6.10.0` : "Can no longer delete permissions" by @erikn69 in https://github.com/spatie/laravel-permission/pull/2759 + +**Full Changelog**: https://github.com/spatie/laravel-permission/compare/6.10.0...6.10.1 + ## 6.10.0 - 2024-11-05 ### What's Changed @@ -882,6 +890,7 @@ The following changes are not "breaking", but worth making the updates to your a + ``` @@ -952,6 +961,7 @@ The following changes are not "breaking", but worth making the updates to your a + ``` diff --git a/src/PermissionRegistrar.php b/src/PermissionRegistrar.php index 643ed92e..cc2e1ca5 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 b2309454..d4364573 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()); + } }