Eloquent does not support this at the moment, you will have to write it as a raw request.
// generates (?,?,?,?),(?,?,?,?),(?,?,?,?),(?,?,?,?) $valueString = implode(',', array_fill(0, count($data), '(' . implode(',', array_fill(0, count($data[0]), '?')) . ')')); $values = []; // Flattens the array foreach($data as $row) { foreach($row as $value) { $values[] = $value; } } // Perform the insert \DB::insert( "insert into `snapshots` (`amodule`, `akey`, `avalue`, `created_at`) values {$values} on duplicate key update", $values );
Keep in mind that to run on duplicate key update , at least one of the inserted values ββmust have a primary key or a unique key.
source share