lundi 1 juillet 2019

save() method only writing last record in foreach loop

 foreach ($updateOrInsert as $subordinate) {

        if ($key = array_search($subordinate, $existingDowns))
        {
         // $update[] = ['id'=>$key,'up'=>$up,'down'=>$subordinate,'status'=>0];
          $hierarchy = Hierarchy::find($key);

          $hierarchy->status = 0;

          $hierarchy->save();
      }
      else{
          $insert[] = ['up'=>$up,'down'=>$subordinate];
      }
  }

Here $key is the id of hierarchies table. the above code only update the last id only. I googled for this problem and spend couple of hours but no luck. Any idea?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire