2016-11-10 34 views
0

我使用laravelcollective的dropdownlist。我想知道如何使用(選定的默認值),如果我從數據庫中獲取數據。這裏跟我的源代碼:從laravelcollective下拉列表?

{!! Form::select('port',$ports,null,['class'=>'form-control']) !!} 

我想要的選擇默認是例如(選擇端口)。

回答

0

首先在你的控制器創建一個列表,並作爲第一元素使用空值「請選擇一個端口」文本:當您將它傳遞給視圖

$ports =['' => 'Please Select a port'] + Port::lists('shortName','id')->toArray(); 

使用它像這樣:

{!! Form::select('port_id',$ports,null,['class' => 'form-control']) !!} 
+0

非常感謝你,它完美的作品 – allaghi