簡體   English   中英

在Laravel中設置正確的選項值

[英]Setting correct option values in Laravel

誰能幫我在Laravel 5.1中的選擇樣式下拉菜單上設置選項變量?

在我的控制器中

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

“空間”視圖看起來像

{!! 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)有沒有一種方法可以默認選擇不顯示任何值?

謝謝,奧特曼

我正在使用Collective HTML生成器,如果有區別的話

嘗試選擇該列作為“名稱”

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

或者您可能需要使用列表將其返回,例如:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM