Skip to content

Commit

Permalink
Merge pull request #7 from adriandmitroca/support-forcedelete
Browse files Browse the repository at this point in the history
Add support for forceDelete()
  • Loading branch information
michaeldyrynda committed Jun 9, 2016
2 parents 5601b55 + 5e53dab commit d7c30c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CascadeSoftDeletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected static function bootCascadeSoftDeletes()
}

foreach ($model->getCascadingDeletes() as $relationship) {
$model->{$relationship}()->delete();
$model->forceDeleting ? $model->{$relationship}()->forceDelete() : $model->{$relationship}()->delete();
}
});
}
Expand Down
16 changes: 16 additions & 0 deletions tests/CascadeSoftDeletesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public function it_cascades_deletes_when_deleting_a_parent_model()
$this->assertCount(0, Tests\Entities\Comment::where('post_id', $post->id)->get());
}

/** @test */
public function it_cascades_deletes_when_force_deleting_a_parent_model()
{
$post = Tests\Entities\Post::create([
'title' => 'How to cascade soft deletes in Laravel',
'body' => 'This is how you cascade soft deletes in Laravel',
]);

$this->attachCommentsToPost($post);

$this->assertCount(3, $post->comments);
$post->forceDelete();
$this->assertCount(0, Tests\Entities\Comment::where('post_id', $post->id)->get());
$this->assertCount(0, Tests\Entities\Post::withTrashed()->where('id', $post->id)->get());
}

/**
* @test
* @expectedException \LogicException
Expand Down

0 comments on commit d7c30c4

Please sign in to comment.