+ /**
+ * Delete all the existing references originating from the given entities.
+ * @param Entity[] $entities
+ */
+ protected function dropReferencesFromEntities(array $entities): void
+ {
+ $IdsByType = [];
+
+ foreach ($entities as $entity) {
+ $type = $entity->getMorphClass();
+ if (!isset($IdsByType[$type])) {
+ $IdsByType[$type] = [];
+ }
+
+ $IdsByType[$type][] = $entity->id;
+ }
+
+ foreach ($IdsByType as $type => $entityIds) {
+ Reference::query()
+ ->where('from_type', '=', $type)
+ ->whereIn('from_id', $entityIds)
+ ->delete();
+ }
+ }
+}