Level 37
If all you need to do is insert the data into a database just use the DB::insert, it should be more efficient.
$dataSet = [];
foreach ($checkBox as $safety) {
$dataSet[] = [
'offer_id' => $id,
'car_id' => $safety,
'car' => 15,
];
}
DB::table('extra')->insert($dataSet);
This would not work if you need the models or listen to events when the new models are created, etc. As far as mass-creating the models and inserting them, I don't believe there is a "Laravel" way.
8 likes