Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yassine-khachlek/de9d2a0ba25becb06972ff24c1dfa656 to your computer and use it in GitHub Desktop.
Save yassine-khachlek/de9d2a0ba25becb06972ff24c1dfa656 to your computer and use it in GitHub Desktop.
$query = "INSERT INTO table_name (" . implode(',', $columns) . ") VALUES " 
. implode(
    ',',
    array_map(function($data) {
        return "(" . implode(",", array_fill(0, count($data) , '?')) . ")";
    }, $datas)
)
. " ON DUPLICATE KEY UPDATE "
. implode(
    ',',
    array_map(function($column) {
        return $column . "=VALUES(" . $column . ')';
    }, $columns)
);

DB::statement($query, array_collapse($datas));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment