Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

haizone's avatar

how send form to object

hi i have this object

[{ "text":"Client1", "Balance1":null, "Balance2":null }, { "text":"Client2", "Balance1":24, "Balance2":0 }]

i what to make a form to edit that object but only one field i do that code but i get only the new field

                                @foreach ($options as $i => $option) 
                                <div class="mx-auto px-8">
                                <div class="font-bold h-6 mt-3 text-gray-600 text-xs leading-8 uppercase" ><span class="text-red-400 mr-1">
                                    </span>{{collect($option)['name']}}*</span>
                                    </div>
                                    <div class="my-2 bg-white p-1 flex border border-gray-200 rounded">     
                                        <input class="p-1 px-2 appearance-none
                                         outline-none w-full text-gray-800" 
                                         name="options[{{$i}}]['text']" 
                                         value="{{collect($option)['text']}}"> 
                                    </div>
                                </div>
                                @endforeach

but i get that when i submit and i want to get alll the fields from the object but i get:

"options" => array:9 [▼ 0 => array:1 [▼ "'text'" => "dsdsd" ] 1 => array:1 [▶] 2 => array:1 [▶] 3 => array:1 [▶]

and i want to get all fileds but without to use hidden input

0 likes
1 reply
Sinnbeck's avatar

You seem to be a bit confused as to what the collect() helper does. It converts/wraps the variable in a collection. Not what you want I assume.

<input class="p-1 px-2 appearance-none
                                         outline-none w-full text-gray-800" 
                                         name="options[{{$i}}]['text']" 
                                         value="{{$option->text}}">

Also your span declaration is off. You have 1 open span and two close? Should probably be

<span class="text-red-400 mr-1">
                                    {{$option->text}}*
</span>

Please or to participate in this conversation.