Skip to content

Commit

Permalink
Fix: #2749 bug "Can no longer delete permissions" (#2759)
Browse files Browse the repository at this point in the history
* Fix: #2749 bug

* Test added
  • Loading branch information
erikn69 authored Nov 8, 2024
1 parent 93477f5 commit 8bb69d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PermissionRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions tests/PermissionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 8bb69d6

Please sign in to comment.