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?
You can do this with model:
Model::insert([
['name' => 'foo'],
['name' => 'bar'],
['name' => 'baz']
]);
But here insert is the same QB method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With