Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nafeeur10's avatar

How to insert data into Database with Eloquent laravel

array:2 [
  0 => array:2 [
    "collection_id" => 93
    "product_id" => 1000092
  ]
  1 => array:2 [
    "collection_id" => 93
    "product_id" => 1000093
  ]
]

Here, collection_id will be same for all products.

I have a database table named collection_products which have only two fields collection_id and product_id. Also have its' correspond Model CollectionProduct.php

Now, how can I insert the above data with Eloquent Model? I don't want to use DB::table()

0 likes
2 replies
MichalOravec's avatar

It means you don't have an array like you described above.

You may insert several records at once by passing an array of arrays.

Please or to participate in this conversation.