Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Laravel form model binding with bootstrap?

I am trying to display a bootstrap formatted form bound to my User model. However, the form-model binding seems to only work out when I use input fields that are not formatted with bootstrap styles.

Here is one without the bootstrap class, which perfectly displays what I have in my db when I open my form with:

{{ Form::model($user) }}

{{ Form::label('name', 'Vorname:')}}
{{ Form::text('name')}}

Here is the second input of this form, now with the bootstrap class. This one does not display the db content.

{{ Form::label('sirname', 'Nachname:')}}
{{ Form::text('sirname', '', array('class'=>'form-control'))}}

How can I fix this? Is there a way to use form-model binding and styling the inputs with bootstrap classes at the same time?

Any help would be appreciated.

Thanks!

like image 848
patrick Avatar asked Dec 20 '22 19:12

patrick


1 Answers

Try the following:

{{ Form::model($user, array('route' => 'xyz')) }}

{{ Form::label('name', 'Vorname:')}}
{{ Form::text('name', null, array('class' => 'form-control'))}}

{{ Form::label('sirname', 'Nachname:')}}
{{ Form::text('sirname', null, array('class' => 'form-control')) }}

{{ Form::close() }}

if you use form model, do not forget to close it.

like image 78
Anam Avatar answered Dec 24 '22 01:12

Anam