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

sger's avatar
Level 4

Input::get("array") with Form request

Hello,

I have a form which contains the following code:

{!! Form::open(array('url'=>"items/create')) !!}
      <div class="form-group">
        {!! Form::label('name') !!}
        {!! Form::text('name', '', array('class' => 'form-control')) !!}
      </div>
      <div class="form-group">
        {!! Form::label('item_id', 'Select Item') !!}
        {!! Form::select('item_id', (['0' => 'Item'] + $items), null, array('class' => 'form-control', 'id' => 'test')) !!}
      </div>
       <div id="items">
        <ul></ul>
      </div> 
      {!! Form::submit('Submit', array('class' => 'btn btn-default')) !!}
      {!! Form::close() !!}
}

every time i select something from Form::select i'm doing an append to list now on post request i want to pass that info which is in form of:

  • item1
  • item2
  • item3
and retrieve the array like name for example Input::get("name") to get the name i want to do something similar with list items.

Any ideas?

0 likes
3 replies
maximl337's avatar
// in your controller
public function create(Request $request) {
    $input = $request->input();

    $array_of_item_ids = $input['item_id'];

}
1 like
Kryptonit3's avatar

just make sure you append the items with an array in the name like

<input type="text" name="name[]" value="blah!" />

Then you can process them in the form request like this

public function rules()
{
    $rules = [
        // put your static input fields here
        'title' => 'required',
    ];
    // your arrays can be done like this
    foreach($this->request->get('name') as $key => $value)
    {
        $rules['name.'.$key] = 'required'; // you can set rules for all the array items
    }

    return $rules;
}
2 likes

Please or to participate in this conversation.