Skip to content

Commit

Permalink
Remove the relation after delete user
Browse files Browse the repository at this point in the history
  • Loading branch information
makladuxbert committed Aug 30, 2017
1 parent 80d4421 commit 12cbbea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/Traits/HasRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ trait HasRoles
public static function bootHasRoles()
{
static::deleting(function ($model) {
$model->roles()->detach();
$model->permissions()->detach();
foreach ($model->roles as $role) {
$role->users()->detach($model);
}
foreach ($model->permissions as $permissions) {
$permissions->users()->detach($model);
}
});
}

Expand Down
5 changes: 2 additions & 3 deletions tests/RoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public function it_has_user_models_of_the_right_class()
$this->assertTrue($this->testUserRole->users->first()->is($this->testUser));
$this->assertInstanceOf(User::class, $this->testUserRole->users->first());

// FIXME mongodb detach
// $this->testUser->delete();
// $this->assertCount(0, $this->testUserRole->users);
$this->testUser->delete();
$this->assertEquals(0, $this->testUserRole->users()->count());
}

/** @test */
Expand Down

0 comments on commit 12cbbea

Please sign in to comment.