Skip to content

Commit 254852e

Browse files
committed
there we go
1 parent 839387a commit 254852e

File tree

2 files changed

+8
-43
lines changed

2 files changed

+8
-43
lines changed

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

tests/Database/DatabaseEloquentIntegrationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,6 @@ public function testTouchingBiDirectionalChaperonedModelUpdatesAllRelatedTimesta
24762476

24772477
public function testCanInsertWithCasts()
24782478
{
2479-
24802479
DB::enableQueryLog();
24812480
Carbon::setTestNow('2025-03-15T07:32:00Z');
24822481

0 commit comments

Comments
 (0)