vendredi 23 septembre 2016

Dropdown created in foreach loop blade not returning data to controller

I'm trying to create a form creating dynamic dropdowns depending on the number of items in the array $ecommerce_categories

{!! Form::open(['route' => 'categories.store', 'method' => 'post', 'id' => 'category_form', 'enctype' => 'multipart/form-data']) !!}




@foreach ($ecommerce_categories as $ecommerce_category)
    <tr>
        <td>  </td>
        <td> {!! Form::select('id', $final_categories, null, ['placeholder' => 'Selecione uma categoria','class' => 'form-control']) !!}</td>

    </tr>
@endforeach

{!! Form::close() !!}

The fields are created but the data is not passing to the controller. When I press the submit button I only get this as the data for the form:

( [_token] => x2IAExFVNBwkrYSU0faV9GpVEUUjMDNuC3KFaZRk [id] =>)

It should be an id for each dropdown created, but it's retuning an empty field.

This is how I'm trying to get the data in the controller:

public function store(Request $request)
{
    $input = $request->all();

    $category = $this->categoryRepository->create($input);

    Flash::success('Category saved successfully.');

    return redirect(route('categories.index'));
}

When I remove the dropdown fields from the for loop, it works perfectly:

{!! Form::open(['route' => 'categories.store', 'method' => 'post', 'id' => 'category_form', 'enctype' => 'multipart/form-data']) !!}



{!! Form::select('id', $final_categories, null, ['placeholder' => 'Selecione uma categoria','class' => 'form-control']) !!}</td>


{!! Form::close() !!}

What is wrong with the for loop?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire