遍历数组时出现问题,它只会更新一条记录,并且我想采取一切措施,因为我想更改表中的顺序
public function updateAll(Request $request)
{
$questionOption1 = QuestionOption::all();
foreach ($questionOption1 as $item) {
$id=$item->id;
foreach ($request->all() as $order1) {
if ($order1['id'] == $id) {
$item->update(['order' => $order1['order']]);
}
}
return response('Update Successful.', 200);
}
// vuejs
eupdate() {
this.questionOptionNew.map((item,index)=>{
item.order = index + 1 ;
});
var url = '/api/update';
axios.post(url,this.questionOptionNew)
.then(response=>{
this.getQuestion();
});
console.log("hola",this.questionOptionNew);
},