Skip to content

Commit 8bb69d6

Browse files
authoredNov 8, 2024··
Fix: #2749 bug "Can no longer delete permissions" (#2759)
* Fix: #2749 bug * Test added
1 parent 93477f5 commit 8bb69d6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed
 

‎src/PermissionRegistrar.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private function getSerializedRoleRelation($permission): array
349349

350350
private function getHydratedPermissionCollection(): Collection
351351
{
352-
$permissionInstance = new ($this->getPermissionClass())();
352+
$permissionInstance = (new ($this->getPermissionClass())())->newInstance([], true);
353353

354354
return Collection::make(array_map(
355355
fn ($item) => (clone $permissionInstance)
@@ -368,7 +368,7 @@ private function getHydratedRoleCollection(array $roles): Collection
368368

369369
private function hydrateRolesCache(): void
370370
{
371-
$roleInstance = new ($this->getRoleClass())();
371+
$roleInstance = (new ($this->getRoleClass())())->newInstance([], true);
372372

373373
array_map(function ($item) use ($roleInstance) {
374374
$role = (clone $roleInstance)

‎tests/PermissionTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,15 @@ public function it_is_retrievable_by_id()
6767

6868
$this->assertEquals($this->testUserPermission->id, $permission_by_id->id);
6969
}
70+
71+
/** @test */
72+
public function it_can_delete_hydrated_permissions()
73+
{
74+
$this->reloadPermissions();
75+
76+
$permission = app(Permission::class)->findByName($this->testUserPermission->name);
77+
$permission->delete();
78+
79+
$this->assertCount(0, app(Permission::class)->where($this->testUserPermission->getKeyName(), $this->testUserPermission->getKey())->get());
80+
}
7081
}

0 commit comments

Comments
 (0)
Please sign in to comment.