Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}