[英]Setting correct option values in Laravel
can anyone help me set the option variables on a select style drop-down in Laravel 5.1? 谁能帮我在Laravel 5.1中的选择样式下拉菜单上设置选项变量?
In my controller I have 在我的控制器中
$buildings = Warf::select('facilityname')
->distinct()
->get();
.
.
.
return view('reports.space', compact('buildings');
the 'space' view looks like “空间”视图看起来像
{!! Form::open() !!}
<div class="well col-sm-6 col-sm-offset-3">
<legend>Spacial Reports</legend>
<div class="form-group">
{!! Form::label('building_', 'Building:') !!}
{!! Form::select('building', $buildings, null, ['class' => 'form-control'])!!}
</div>
.
.
.
<div class="form-group">
{!! Form::submit('Submit', ['class' => 'btn btn-primary form-control']) !!}
</div>
</div>
{!! Form::close() !!}
However this results in the following HTML 但是,这导致以下HTML
<div class="form-group">
<label for="building_">Building:</label>
<select class="form-control" name="building"><option value="0">{"facilityname":"WARF"}</option></select>
</div>
Questions: A) How can I get just "WARF" to show up in the dropdown? 问题:A)如何仅在下拉菜单中显示“ WARF”? B) Is there a way to default the selection to show no values?
B)有没有一种方法可以默认选择不显示任何值?
Thanks, Otterman 谢谢,奥特曼
I am using the Collective Html generator if that makes a difference 我正在使用Collective HTML生成器,如果有区别的话
Try selecting the column as "name" 尝试选择该列作为“名称”
$buildings = Warf::select('facilityname as name')
->distinct()
->get();
or you might need to return that using lists, something like: 或者您可能需要使用列表将其返回,例如:
$buildings = Warf::select('facilityname as name')
->distinct()
->lists('name','id')->all() //
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.