简体   繁体   中英

form model binding in laravel 5.2

I have been reading about form model binding https://laravelcollective.com/docs/5.0/html#form-model-binding

It's very cool to populate DB values in html form. I tried like this and this works fantastic.

{{ Form::model($university,array('url' => admin_path('universities/edit'),'id' => 'add_university','name' =>'add_university','data-validate'=>"parsley")) }}
    {{ Form::label('university_name', 'University name',array('class'=>'control-label')) }}
    {{ Form::text('university_name')}}
{{Form::close()}}

But the problem is here, Cause i want to add more attributes in input like class SO i am using

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

If i leave blank value column then nothing populate in textbox and if i using like this

{{ Form::label('university_name', 'University name',array('class'=>'control-label')) }}
{{ Form::text('university_name',$university->university_name,array('class' => 'form-control'))}}

Then what is use of model binding. Please explain. Thanks

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

It should be:

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

'' means the real string, not null.
thanks, mathielo, for helping me on grammar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM