@@ -642,48 +642,11 @@ public function insertOrIgnore(array $values)
642
642
* Insert a number of records, merging in default attributes,
643
643
* adding timestamps, and converting casts to raw values.
644
644
*
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>>
647
647
*/
648
648
public function castBeforeInsert (array $ values )
649
649
{
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
-
687
650
if (empty ($ values )) {
688
651
return [];
689
652
}
@@ -692,13 +655,16 @@ public function castBeforeInsert(array $values)
692
655
$ values = [$ values ];
693
656
}
694
657
695
- $ this ->model ->unguard (function () use (&$ values ) {
658
+ $ this ->model ->unguarded (function () use (&$ values ) {
696
659
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 ();
698
664
}
699
665
});
700
666
701
- return dd ( $ this ->addTimestampsToUpsertValues ($ this -> addUniqueIdsToUpsertValues ( $ values)) );
667
+ return $ this ->addTimestampsToUpsertValues ($ values );
702
668
}
703
669
704
670
/**
0 commit comments