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

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -