Search code examples
phplaravelformbuilder

Laravel 4 form builder creating 'list' attribute input


I'm trying to use the form builder to create the following line of code:

<input type="text" list="book_type" id="b_type" name="book_type">

However, I have no idea how do create the list type.

And this won't work:

{{ Form::input('list', 'book_type' }}

Solution

  • This should give you the HTML you provided:

    {{ Form::text('book_type', null, array('id' => 'b_type', 'list' => 'book_type')) }}
    

    The third parameter to the text method is an array of attributes to add to the input element. list is an attribute, so it is included. Also, the id is different than the name, so it needs to be specified in the attribute array, as well.

    If you'd prefer to stick with the input method, the attribute array is the fourth parameter:

    {{ Form::input('text', 'book_type', null, array('id' => 'b_type', 'list' => 'book_type')) }}