在 Laravel 中设置正确的选项值

Setting correct option values in Laravel

谁能帮我在 Laravel 5.1 中的 select 样式下拉菜单中设置选项变量?

在我的控制器中我有

$buildings = Warf::select('facilityname')
    ->distinct()
    ->get();
.
.
.
return view('reports.space', compact('buildings');

'space' 视图看起来像

{!! 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() !!}

但是这会导致以下结果 HTML

<div class="form-group">
    <label for="building_">Building:</label>
    <select class="form-control" name="building"><option value="0">{"facilityname":"WARF"}</option></select>
</div>

问题: A) 我怎样才能让 "WARF" 出现在下拉列表中? B) 有没有办法让 selection 默认不显示任何值?

谢谢, 奥特曼

我正在使用 Collective Html 生成器,如果有影响的话

尝试将列选择为 "name"

$buildings = Warf::select('facilityname as name')
->distinct()
->get();

或者您可能需要 return 使用列表,例如:

$buildings = Warf::select('facilityname as name')
->distinct()
->lists('name','id')->all() //