0
在多select中顯示選定項目時出現問題。Laravel表單構建器多選select items
有一個 'index.blade.php' 實體視圖
子視圖片段內一個 'filter.blade.php' 子圖,形成輸入,幾個多選擇之一:
<div class="col-lg-4 col-md-4 form-group">
{!! Form::label('subcategories', trans('art-work.subcategory'), ['class' => 'control-label']) !!}
{!! Form::select('subcategories[]', $subcategories, $_subcategories,
[
'id' => 'subcategories',
'class' => 'form-control select2',
'multiple' => 'multiple',
'data-placeholder' => trans('crud.choose'),
]) !!}
</div>
....
{{ Log::info('subcategories', $_subcategories) }}
控制器動作,這從處理請求輸入來過濾結果
public function filter(Request $request)
{
$this->validate($request, $this->filterRules);
$filters = [
'category_id' => (int) $request->category_id,
'subcategories' => $request->subcategories,
'grades' => $request->grades,
'students' => $request->students,
'professors' => $request->professors,
];
$works = ArtWork::filtered($filters);
$subcategories = Category::where('category_id', $filters['category_id'])
->get()
->pluck('title', 'id')
->toArray();
return view('panel.art-work.index', [
'works' => $works,
'subcategories' => $subcategories,
'_category' => $filters['category_id'],
'_subcategories' => $filters['subcategories'],
'_grades' => $filters['grades'],
'_students' => $filters['students'],
'_professors' => $filters['professors'],
'_filter' => true,
]);
}
因此,當過濾器形式被提交到控制器,並用像「_subcategories」中的變量的視圖被示出,昭在多重選擇中從請求中選擇ID。但沒有選擇。
奇怪的是,我堅持...
感謝