mardi 11 décembre 2018

multiple records in json update laravel database

I have a problem when going through my array, it only updates me just one record and I would like to act everything since I want the order to change in my table

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);

},

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire