Laravel 4 blade drop-down list class attribute

2019-02-02 07:15发布

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>

2条回答
孤傲高冷的网名
2楼-- · 2019-02-02 07:55

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')) }}
查看更多
贪生不怕死
3楼-- · 2019-02-02 07:57
{{ Form::select('product_id', $productList, null, array('class' => 'form-control')) }}

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

查看更多
登录 后发表回答