【发布时间】:2018-04-11 05:08:02
【问题描述】:
我希望在我的编辑表单中选择下拉列表值。
在我的控制器中
public function edit($id)
{
$vedit = DB::table('vehicles')->where('id', $id)->first();
$cartype= DB::table('car_category')->pluck('cartype');
return view('vehicles.edit', compact('vedit','cartype'));
}
在视图中
{{ Form::label('Vehicle Type', 'Vehicle Type') }}
<select name="vehicle_type" class="form-control">
@foreach($cartype as $cartypes)
<option value="{{ $cartypes}}">{{ $cartypes}}</option>
@endforeach
</select>
我怎样才能做到这一点?
【问题讨论】:
-
我已经在我的控制器中尝试了代码,
$categories = [''=>''] + Car::pluck('cartype')->all(); return view('vehicles.edit', compact('vedit','categories')); -
但它也不起作用,它在视图中添加了另一个空选项
-
试试
pluck('cartype', 'id')!! -
不,它不工作还创建新选项为空
-
对不起,我之前没有得到这个问题:p,你是怎么得到它的?