1

I use dropdownlist from laravelcollective. I am wondering how I can use (Selected Default) with this if I fetch data from a database. Here follows my source code:

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

The selected default that I want is for example (Select Port).

David L
  • 32,885
  • 8
  • 62
  • 93
allaghi
  • 165
  • 3
  • 12

2 Answers2

3

First of all create a list in your controller and use as a first element the "Please select a port" text with empty value:

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

After you pass it to the view use it like this:

{!! Form::select('port_id',$ports,null,['class' => 'form-control']) !!}
H.Kontodios
  • 246
  • 1
  • 7
0

The correct is to use attribute placeholder in dropdown.

{!! Form::select('port', $ports, null, ['placeholder' => 'Select a Port', 'class'=>'form-control']) !!}
Diego Souza
  • 142
  • 1
  • 6