@@ -60,13 +60,6 @@ class Builder implements BuilderContract
60
60
*/
61
61
public $ pendingAttributes = [];
62
62
63
- /**
64
- * Indicates if attributes, timestamps, and unique IDs should be merged before insert.
65
- *
66
- * @var bool
67
- */
68
- public $ mergeAttributesBeforeInsert = false ;
69
-
70
63
/**
71
64
* The relationships that should be eager loaded.
72
65
*
@@ -596,56 +589,51 @@ public function findOr($id, $columns = ['*'], ?Closure $callback = null)
596
589
}
597
590
598
591
/**
599
- * Insert new records into the database.
592
+ * Merge in Model's default attributes, set timestamps,
593
+ * cast any values, and then insert into the database.
600
594
*
595
+ * @param array<int, array<string, mixed>> $values
601
596
* @return bool
602
597
*/
603
- public function insert (array $ values )
598
+ public function hydrateAndInsert (array $ values )
604
599
{
605
- if ($ this ->mergeAttributesBeforeInsert ) {
606
- $ values = $ this ->castBeforeInsert ($ values );
607
- }
608
-
609
- return $ this ->forwardCallTo ($ this ->query , 'insert ' , [$ values ]);
600
+ return $ this ->insert ($ this ->hydrateForInsert ($ values ));
610
601
}
611
602
612
603
/**
613
- * Insert a new record and get the value of the primary key.
604
+ * Merge in Model's default attributes, set timestamps,
605
+ * cast any values, and then insert into the database,
606
+ * ignoring errors.
614
607
*
615
- * @param string|null $sequence
608
+ * @param array<int, array< string, mixed>> $values
616
609
* @return int
617
610
*/
618
- public function insertGetId (array $ values, $ sequence = null )
611
+ public function hydrateAndInsertOrIgnore (array $ values )
619
612
{
620
- if ($ this ->mergeAttributesBeforeInsert ) {
621
- $ values = $ this ->castBeforeInsert ([$ values ])[0 ];
622
- }
623
-
624
- return $ this ->forwardCallTo ($ this ->query , 'insertGetId ' , [$ values , $ sequence ]);
613
+ return $ this ->insertOrIgnore ($ this ->hydrateForInsert ($ values ));
625
614
}
626
615
627
616
/**
628
- * Insert new records into the database while ignoring errors.
617
+ * Merge in Model's default attributes, set timestamps,
618
+ * cast any values, and then insert into the database,
619
+ * returning the ID of the new record.
629
620
*
621
+ * @param array<string, mixed> $values
630
622
* @return int
631
623
*/
632
- public function insertOrIgnore (array $ values )
624
+ public function hydrateAndInsertGetId (array $ values )
633
625
{
634
- if ($ this ->mergeAttributesBeforeInsert ) {
635
- $ values = $ this ->castBeforeInsert ($ values );
636
- }
637
-
638
- return $ this ->forwardCallTo ($ this ->query , 'insertOrIgnore ' , [$ values ]);
626
+ return $ this ->insertGetId ($ this ->hydrateForInsert ([$ values ])[0 ]);
639
627
}
640
628
641
629
/**
642
- * Insert a number of records, merging in default attributes,
630
+ * Enrich values by merging in the Model's default attributes,
643
631
* adding timestamps, and converting casts to raw values.
644
632
*
645
633
* @param array<int, array<string, mixed>> $values
646
634
* @return array<int, array<string, mixed>>
647
635
*/
648
- public function castBeforeInsert (array $ values )
636
+ public function hydrateForInsert (array $ values )
649
637
{
650
638
if (empty ($ values )) {
651
639
return [];
@@ -1915,20 +1903,6 @@ public function withAttributes(Expression|array|string $attributes, $value = nul
1915
1903
return $ this ;
1916
1904
}
1917
1905
1918
- /**
1919
- * Indicate if insert methods should merge in default attributes,
1920
- * add timestamps, and converting casts to raw values.
1921
- *
1922
- * @param bool $mergeBeforeInsert
1923
- * @return $this
1924
- */
1925
- public function mergeAttributesBeforeInsert ($ mergeBeforeInsert = true )
1926
- {
1927
- $ this ->mergeAttributesBeforeInsert = $ mergeBeforeInsert ;
1928
-
1929
- return $ this ;
1930
- }
1931
-
1932
1906
/**
1933
1907
* Apply query-time casts to the model instance.
1934
1908
*
0 commit comments