I am trying to build an API to store and retrieve MCQ exam papers. I am using laravel resource class to send handle Json data. I need to insert 40 records into MySQL databas
insert select query with update models array field
$newModelsArray=ModelTable::where(....)->get();
foreach ($newModelsArray as $objectItr) {
$newObjectItr = $objectItr->replicate();
$newObjectItr->field=newValue;
$newObjectItr->save();
}
and there you'll update and save in to the table (clone it back to the database) ->replicate() will clone the modelObject and the ->save() will add it to the database inside the loop !
Thanks Ali