Level 75
It's same way like with DB::table(), but instead of that you can use model.
https://laravel.com/docs/8.x/queries#insert-statements
CollectionProduct::insert($data);
where $data is your array.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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()
It's same way like with DB::table(), but instead of that you can use model.
https://laravel.com/docs/8.x/queries#insert-statements
CollectionProduct::insert($data);
where $data is your array.
Please or to participate in this conversation.