Skip to content

Commit d7c30c4

Browse files
Merge pull request #7 from adriandmitroca/support-forcedelete
Add support for forceDelete()
2 parents 5601b55 + 5e53dab commit d7c30c4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/CascadeSoftDeletes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected static function bootCascadeSoftDeletes()
3434
}
3535

3636
foreach ($model->getCascadingDeletes() as $relationship) {
37-
$model->{$relationship}()->delete();
37+
$model->forceDeleting ? $model->{$relationship}()->forceDelete() : $model->{$relationship}()->delete();
3838
}
3939
});
4040
}

tests/CascadeSoftDeletesIntegrationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ public function it_cascades_deletes_when_deleting_a_parent_model()
5353
$this->assertCount(0, Tests\Entities\Comment::where('post_id', $post->id)->get());
5454
}
5555

56+
/** @test */
57+
public function it_cascades_deletes_when_force_deleting_a_parent_model()
58+
{
59+
$post = Tests\Entities\Post::create([
60+
'title' => 'How to cascade soft deletes in Laravel',
61+
'body' => 'This is how you cascade soft deletes in Laravel',
62+
]);
63+
64+
$this->attachCommentsToPost($post);
65+
66+
$this->assertCount(3, $post->comments);
67+
$post->forceDelete();
68+
$this->assertCount(0, Tests\Entities\Comment::where('post_id', $post->id)->get());
69+
$this->assertCount(0, Tests\Entities\Post::withTrashed()->where('id', $post->id)->get());
70+
}
71+
5672
/**
5773
* @test
5874
* @expectedException \LogicException

0 commit comments

Comments
 (0)