src/Console/CommandTrait.php
protected function updateOrInsertMultiple($tableName, $data)
    {
        $fields = '`' . implode('`,`', array_keys($data[0])) . '`';
        // Create strings for variables
        $questionMarks = '';
        $updateList = '';
        foreach (array_keys($data[0]) as $key) {
            $updateList .= '`' . $key . '`' . '=VALUES(' . '`' . $key . '`' . '),';
            $questionMarks .= '?,';
        }
        // Remove last extra comma
        $updateList = rtrim($updateList, ',');
        $questionMarks = rtrim($questionMarks, ',');

        // If files were not in sync, there may be missing entries in some tables
        $sql = /** @lang text */
            'INSERT IGNORE INTO ' . $tableName . ' (' . $fields . ') ';
        $sql .= 'VALUES ' . PHP_EOL;
        // Set placeholders
        $sql .= '(' . $questionMarks . ')';
        for ($i = 1; $i < count($data); $i++) {
            $sql .= ',' . PHP_EOL . '(' . $questionMarks . ')';
        }
        $sql .= PHP_EOL;
        $valueArray = array();
        foreach ($data as $rows) {
            foreach ($rows as $key => $value) {
                $valueArray[] = $value;
            }
        }
        // Set action on duplicate key updates
        $sql .= "ON DUPLICATE KEY UPDATE ";
        $sql .= $updateList;

        return DB::insert($sql, $valueArray);
    }
protected function updateOrInsertMultiple($tableName, $data)
    {
        $fields = '`' . implode('`,`', array_keys($data[0])) . '`';
        // Create strings for variables
        $questionMarks = '';
        $updateList = '';
        foreach (array_keys($data[0]) as $key) {
            $updateList .= '`' . $key . '`' . '=VALUES(' . '`' . $key . '`' . '),';
            $questionMarks .= '?,';
        }
        // Remove last extra comma
        $updateList = rtrim($updateList, ',');
        $questionMarks = rtrim($questionMarks, ',');

        // If files were not in sync, there may be missing entries in some tables
        $sql = /** @lang text */
            'INSERT IGNORE INTO ' . $tableName . ' (' . $fields . ') ';
        $sql .= 'VALUES ' . PHP_EOL;
        // Set placeholders
        $sql .= '(' . $questionMarks . ')';
        for ($i = 1; $i < count($data); $i++) {
            $sql .= ',' . PHP_EOL . '(' . $questionMarks . ')';
        }
        $sql .= PHP_EOL;
        $valueArray = array();
        foreach ($data as $rows) {
            foreach ($rows as $key => $value) {
                $valueArray[] = $value;
            }
        }
        // Set action on duplicate key updates
        $sql .= "ON DUPLICATE KEY UPDATE ";
        $sql .= $updateList;

        return DB::insert($sql, $valueArray);
    }
Create and run a single SQL INSERT query for multiple rows of data.
$data argument is an array of database row arrays in key=>value pairs.
This speeds up inserts ~50 times compared to line-by-line inserts.

Note: The $data must be an array of arrays and have at least 2 elements.

@param  string $tableName
@param  array (array()) $data
@return boolean