I have an array and an id of another table. I need each array item to be a new record. Each of these records needs to include one item from the array and the id of the other table. How do I make the store function loop through the array and each time grab the other table id and insert into the database?
The View
<tablv>
<thead>
<tr>
<td>MFG</td>
</tr>
</thead>
<tbody>
<tr v-for="hp in ordered_handpieces">
<td>
<input type="checkbox" :value="hp.id" v-model="hp_id"><span>{{hp.mfg.mfg_name}}</span>
</td>
</tr>
</tbody>
</table>
The Script
data: function() {
return {
hp_wo_id:'',
hp_id:[],
}
},
methods: {
onSubmit(){
axios.post('/hp_wo_unit', this.$data)
}
}
The Controller
public function store(Request $request){
foreach (request(['hp_id']) as $hp_id) {
hp_wo_unit::create(request(['hp_wo_id'],$hp_id));
}
return $request;
}