Skip to content

Commit ec35cab

Browse files
authored
Merge pull request #4543 from Laravel-Backpack/trigger-delete-event-for-hasmany-deleted-items
trigger the delete events for each of related deleted model
2 parents bea3042 + 0b05561 commit ec35cab

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/app/Library/CrudPanel/Traits/Create.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private function handleManyRelationItemRemoval($modelInstance, $removedEntries,
264264
// developer set force_delete => true, so we don't care if it's nullable or not,
265265
// we just follow developer's will
266266
if ($forceDelete) {
267-
return $removedEntries->delete();
267+
return $removedEntries->lazy()->each->delete();
268268
}
269269

270270
// get the default that could be set at database level.
@@ -273,7 +273,7 @@ private function handleManyRelationItemRemoval($modelInstance, $removedEntries,
273273
// if column is not nullable in database, and there is no column default (null),
274274
// we will delete the entry from the database, otherwise it will throw and ugly DB error.
275275
if (! $relationColumnIsNullable && $dbColumnDefault === null) {
276-
return $removedEntries->delete();
276+
return $removedEntries->lazy()->each->delete();
277277
}
278278

279279
// if column is nullable we just set it to the column default (null when it does exist, or the default value when it does).
@@ -316,10 +316,10 @@ private function createManyEntries($entry, $relation, $relationMethod, $relation
316316
$this->createRelationsForItem($item, $relationInputs);
317317
}
318318

319-
// use the collection of sent ids to match agains database ids, delete the ones not found in the submitted ids.
319+
// use the collection of sent ids to match against database ids, delete the ones not found in the submitted ids.
320320
if (! empty($relatedItemsSent)) {
321321
// we perform the cleanup of removed database items
322-
$entry->{$relationMethod}()->whereNotIn($relatedModelLocalKey, $relatedItemsSent)->delete();
322+
$entry->{$relationMethod}()->whereNotIn($relatedModelLocalKey, $relatedItemsSent)->lazy()->each->delete();
323323
}
324324
}
325325
}

0 commit comments

Comments
 (0)