mercredi 14 octobre 2015

how to save multi array in db laravel

im getting these data from service

value = 1:1,2:0,3:1,4:0,5:1,6:1,7:0,8:0,9:1,10:0

and i splitt it using arrayas

$result = array();
                foreach (explode(',',$value) as $sub)
                {
                    $subAry = explode(':',$sub);
                    $result[$subAry[0]] = $subAry[1];

                }
                return $result;

here how its return
  "1": "1",
  "2": "0",
  "3": "1",
  "4": "0",
  "5": "1",
  "6": "1",
  "7": "0",
  "8": "0",
  "9": "1",
  "10": "0"
}

i want to save these values in table in two columns, please advice

first number set should goes to $value column and other one should goes to $type column,

here is my controller,

$DriverPreDepartureItems = new DriverPreDepartureItems();
                    $DriverPreDepartureItems->user_id = $driver_id->id;

                    $DriverPreDepartureItems->shift_id = $find_shift->id;
                    $DriverPreDepartureItems->type = ;
                    $DriverPreDepartureItems->value = ;

                    $DriverPreDepartureItems->save();

pls advice



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire