@@ -642,48 +642,11 @@ public function insertOrIgnore(array $values)
642642 * Insert a number of records, merging in default attributes,
643643 * adding timestamps, and converting casts to raw values.
644644 *
645- * @param array<int, < array<string, mixed>> $values
646- * @return array
645+ * @param array<int, array<string, mixed>> $values
646+ * @return array<int, array<string, mixed>>
647647 */
648648 public function castBeforeInsert (array $ values )
649649 {
650- /*
651- if (empty($values)) {
652- return [];
653- }
654-
655- if (! is_array(reset($values))) {
656- $values = [$values];
657- }
658-
659- $modelInstance = $this->newModelInstance();
660- $timestampColumns = [];
661-
662- if ($modelInstance->usesTimestamps()) {
663- $now = $modelInstance->freshTimestamp();
664-
665- if ($createdAtColumn = $modelInstance->getCreatedAtColumn()) {
666- $timestampColumns[$createdAtColumn] ??= $now;
667- }
668- if ($updatedAtColumn = $modelInstance->getUpdatedAtColumn()) {
669- $timestampColumns[$updatedAtColumn] ??= $now;
670- }
671- }
672-
673- $this->model->unguarded(function () use (&$values, $timestampColumns) {
674- foreach ($values as $key => $value) {
675- $newModelInstance = tap(
676- $this->newModelInstance(array_merge($timestampColumns, $value)),
677- fn (Model $model) => $model->setUniqueIds()
678- );
679- $values[$key] = $newModelInstance->getAttributes();
680- }
681- });
682-
683- dd($values);
684- return $values;
685- */
686-
687650 if (empty ($ values )) {
688651 return [];
689652 }
@@ -692,13 +655,16 @@ public function castBeforeInsert(array $values)
692655 $ values = [$ values ];
693656 }
694657
695- $ this ->model ->unguard (function () use (&$ values ) {
658+ $ this ->model ->unguarded (function () use (&$ values ) {
696659 foreach ($ values as $ key => $ rowValues ) {
697- $ values [$ key ] = $ this ->newModelInstance ($ rowValues )->getAttributes ();
660+ $ values [$ key ] = tap (
661+ $ this ->newModelInstance ($ rowValues ),
662+ fn ($ model ) => $ model ->setUniqueIds ()
663+ )->getAttributes ();
698664 }
699665 });
700666
701- return dd ( $ this ->addTimestampsToUpsertValues ($ this -> addUniqueIdsToUpsertValues ( $ values)) );
667+ return $ this ->addTimestampsToUpsertValues ($ values );
702668 }
703669
704670 /**
0 commit comments