Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for forceDelete() #7

Merged
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
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