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 -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -