init commit
All checks were successful
build-api-image / build (push) Successful in 51s

This commit is contained in:
Antonio Lopes dos Santos
2026-08-04 16:52:02 -03:00
commit afec302c3e
11594 changed files with 1636728 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
class SeederUtil
{
public static function saveList($model, $items, $identifierKeys = [], $deleteIfNotPresent = false)
{
if (is_string($identifierKeys)) {
$identifierKeys = [$identifierKeys];
}
$ids = [];
foreach ($items as $item) {
$identifiers = [];
foreach ($identifierKeys as $key) {
$identifiers[$key] = $item[$key];
}
if (empty($identifiers)) {
$ids[] = $model::create($item)->id;
continue;
}
$ids[] = $model::updateOrCreate($identifiers, $item)->id;
}
if ($deleteIfNotPresent && !empty($ids)) {
$idsToDelete = $model::whereNotIn('id', $ids)->pluck('id');
if (!empty($idsToDelete)) {
$model::destroy($idsToDelete);
}
}
}
}