在foreach循环刀片中创建的下拉列表不会将数据返回到控制器

时间:2016-09-24 03:41:20

标签: php laravel-5

我尝试创建一个表单来创建动态下拉列表,具体取决于数组中的项目数量$ ecommerce_categories

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

{{ Form::token() }}


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

    </tr>
@endforeach

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

创建字段但数据未传递给控制器​​。 当我按下提交按钮时,我只将其作为表格的数据:

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

它应该是每个下拉列表的ID,但它会重新调整空字段。

这就是我试图在控制器中获取数据的方式:

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

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

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

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

当我从for循环中删除下拉字段时,它完美地运行:

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

{{ Form::token() }}

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


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

for循环有什么问题?

0 个答案:

没有答案