Answers for "insert multiple rows laravel"

PHP
5

laravel 8 insert multiple rows

$array = [
     ['value' => "value1", 'status_id' => 1],
     ['value' => "value2", 'status_id' => 2]
];

ModelName::insert($array);
// or
DB::table('table_name')->insert($array);
Posted by: Guest on September-02-2021
0

insert multiple rows laravel

$data = [
    ['user_id'=>'Coder 1', 'subject_id'=> 4096],
    ['user_id'=>'Coder 2', 'subject_id'=> 2048],
    //...
];

Model::insert($data); // Eloquent approach
DB::table('table')->insert($data); // Query Builder approach
Posted by: Guest on July-15-2021
0

how to insert multiple rows in mysql using laravel

/*
It is really easy to do a bulk insert in Laravel with or without the query builder.
You can use the following official approach.
*/


Entity::upsert([
    ['name' => 'Pierre Yem Mback', 'city' => 'Eseka', 'salary' => 10000000],
    ['name' => 'Dial rock 360', 'city' => 'Yaounde', 'salary' => 20000000],
    ['name' => 'Ndibou La Menace', 'city' => 'Dakar', 'salary' => 40000000]
], ['name', 'city'], ['salary']);
Posted by: Guest on December-18-2020

Code answers related to "insert multiple rows laravel"

Browse Popular Code Answers by Language