32

Laravel blade drop down list class attribute not working.

I cannot find any reference to class or assigning attributes to select / drop-down lists in the documentation.

http://www.laravel.com/docs/html#drop-down-lists

Examples tried:

{{ Form::select('product_id', $productList, array('class'=>'form-control')) }}

{{ Form::select('product_id', $productList, $attributes = array('class'=>'form-control')) }}

Both return the same html but without the class attribute:

<select id="product_id" name="product_id">
    ... Option Stuff ...
</select>
haakym
  • 12,050
  • 12
  • 70
  • 98
Gravy
  • 12,264
  • 26
  • 124
  • 193

2 Answers2

75
{{ Form::select('product_id', $productList, null, array('class' => 'form-control')) }}

The third parameter is the key of the currently selected option. Defaults to null.

Bastian Hofmann
  • 2,485
  • 19
  • 19
  • 4
    Thanks for that... I wish that something as simple as this would be written in the documentation!!! – Gravy Aug 30 '13 at 11:21
  • 2
    You can always check the source. If you are using sublime text hit `cmd + t` and type `FormBuilder`. Remember the framework is part of your application, just because you can't directly change the source code doesn't mean that you should not be familiar with the code in there. – Bastian Hofmann Sep 05 '13 at 17:44
0

First get and create list in Controller for example:

$username_lists  = Users::lists('username','id');

pass data to view by:

 return View::make('layouts.customers')
            ->with('username_lists', $username_lists);

now get in view:

{{ Form::select('username_lists', $username_lists, null, array('class' => 'form-control')) }}
DolDurma
  • 15,753
  • 51
  • 198
  • 377