Reputation: 4029
I have multidimensional array and I want to insert all the data in one query with my model, I know I can do it with DB
query builder class, like
DB::table('table')->insert([
['name' => 'foo'],
['name' => 'bar'],
['name' => 'baz']
]);
but how can I do it with model?
Model::create()
doesn't insert multiple records, also I don't want to insert items with loop. is it possible to do this with eloquent?
Upvotes: 4
Views: 10823
Reputation: 163968
You can do this with model:
Model::insert([
['name' => 'foo'],
['name' => 'bar'],
['name' => 'baz']
]);
But here insert is the same QB method.
Upvotes: 9