@@ -615,6 +615,11 @@ public function findOr($id, $columns = ['*'], ?Closure $callback = null)
615
615
'insertusing',
616
616
'insertorignoreusing',
617
617
*/
618
+ /**
619
+ * Insert new records into the database.
620
+ *
621
+ * @return bool
622
+ */
618
623
public function insert (array $ values )
619
624
{
620
625
if ($ this ->mergeAttributesBeforeInsert ) {
@@ -625,9 +630,10 @@ public function insert(array $values)
625
630
}
626
631
627
632
/**
628
- * @param array $values
629
- * @param $sequence
630
- * @return int|mixed
633
+ * Insert a new record and get the value of the primary key.
634
+ *
635
+ * @param string|null $sequence
636
+ * @return int
631
637
*/
632
638
public function insertGetId (array $ values , $ sequence = null )
633
639
{
@@ -638,17 +644,31 @@ public function insertGetId(array $values, $sequence = null)
638
644
return $ this ->forwardCallTo ($ this ->query , 'insertGetId ' , [$ values , $ sequence ]);
639
645
}
640
646
647
+ /**
648
+ * Insert new records into the database while ignoring errors.
649
+ *
650
+ * @return int
651
+ */
652
+ public function insertOrIgnore (array $ values )
653
+ {
654
+ if ($ this ->mergeAttributesBeforeInsert ) {
655
+ $ values = $ this ->castBeforeInsert ($ values );
656
+ }
657
+
658
+ return $ this ->forwardCallTo ($ this ->query , 'insertGetId ' , [$ values ]);
659
+ }
660
+
641
661
/**
642
662
* Insert a number of records, merging in default attributes,
643
663
* adding timestamps, and converting casts to raw values.
644
664
*
645
- * @param list <array<string, mixed>> $values
665
+ * @param array<int, <array<string, mixed>> $values
646
666
* @return array
647
667
*/
648
668
public function castBeforeInsert ($ values )
649
669
{
650
670
if (empty ($ values )) {
651
- [];
671
+ return [];
652
672
}
653
673
654
674
if (! is_array (reset ($ values ))) {
@@ -2244,13 +2264,6 @@ public function __call($method, $parameters)
2244
2264
return $ this ->callNamedScope ($ method , $ parameters );
2245
2265
}
2246
2266
2247
- if (in_array ($ lowerCaseMethod = strtolower ($ method ), $ this ->passthru )) {
2248
- if ($ this ->mergeAttributesBeforeInsert && in_array ($ lowerCaseMethod , $ this ->mergeBeforeInsertPassThru )) {
2249
- $ parameters [0 ] = $ this ->castBeforeInsert ($ parameters [0 ])[0 ];
2250
- }
2251
- return $ this ->toBase ()->{$ method }(...$ parameters );
2252
- }
2253
-
2254
2267
$ this ->forwardCallTo ($ this ->query , $ method , $ parameters );
2255
2268
2256
2269
return $ this ;
0 commit comments