php - Laravel save multiple records -
i've got array within arrays , add it.
$options = $request->options; foreach ($options $option) { $option['poll_id'] = $this->id; } dd($options);
but reason not add array.
so receive this:
array:1 [ 0 => array:1 [ "name" => "testtest" ] ]
but expect this:
array:1 [ 0 => array:1 [ "name" => "testtest", "poll_id" => 1 ] ]
you're not changing $options
foreach
destroying $option
each iteration. try instead:
$options = []; foreach ($request->options $key => $value) { $options[$key]['poll_id'] = $this->id; }
Comments
Post a Comment