File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 22
33namespace App \Helpers ;
44
5+ use App \Models \Like ;
56use App \Models \Reply ;
67use Illuminate \Database \Eloquent \Relations \MorphMany ;
78
@@ -25,7 +26,11 @@ public function latestReplies(int $amount = 5)
2526
2627 public function deleteReplies ()
2728 {
28- $ this ->repliesRelation ()->delete ();
29+ // We need to explicitly iterate over the repies and delete them
30+ // separately because all related models need to be deleted.
31+ foreach ($ this ->repliesRelation ()->get () as $ reply ) {
32+ $ reply ->delete ();
33+ }
2934 }
3035
3136 /**
Original file line number Diff line number Diff line change @@ -189,7 +189,11 @@ public function latestReplies(int $amount = 3)
189189
190190 public function deleteReplies ()
191191 {
192- $ this ->replyAble ()->delete ();
192+ // We need to explicitly iterate over the replies and delete them
193+ // separately because all related models need to be deleted.
194+ foreach ($ this ->replyAble ()->get () as $ reply ) {
195+ $ reply ->delete ();
196+ }
193197 }
194198
195199 public function countReplies (): int
You can’t perform that action at this time.
0 commit comments