以下代码是我的用户个人资料管理表单,我想用input
变量填充$profile
代码。
{{ $profile }}
可以回显用户表的所有字段。但是我无法使用此变量填充input
标签。
结果:{"id":"1","username":"mahdi","name":"Mahdi","family":"Pishguy","email":"name@gmail.com"}
我的表格:
{{ Form::open(array('route' => 'admin.profile.update', $profile->id , 'method' => 'PUT','class'=>'navbar-form navbar-right', 'role' =>'search')) }}
<div class="form-group rtl">
<div>Your Username: <b> {{ $profile->username }} </b></div><br />
{{ Form::label('name' , 'name: ') }}
{{ Form::text('name', Input::old('name'), array('id'=>'email', 'class' => 'form-control')) }}
{{ Form::label('family' , 'family: ') }}
{{ Form::text('family', Input::old('family'), array('placeholder'=>'sss', 'id'=>'email', 'class' => 'form-control')) }}
<p>
{{ Form::submit('Submit', array('id'=>'submit','class'=>'btn btn-default' , 'style'=>'float:left')) }}
</p>
</div>
{{ Form::close() }}
答案 0 :(得分:2)
很容易,请参阅Form Model Binding in the docs
您的代码应该是这样的:
{{ Form::model($profile, array('route' => 'admin.profile.update', $profile->id , 'method' => 'PUT','class'=>'navbar-form navbar-right', 'role' =>'search')) }}
<div class="form-group rtl">
<div>Your Username: <b> {{ $profile->username }} </b></div><br />
{{ Form::label('name' , 'name: ') }}
{{ Form::text('name', Input::old('name'), array('id'=>'email', 'class' => 'form-control')) }}
{{ Form::label('family' , 'family: ') }}
{{ Form::text('family', Input::old('family'), array('placeholder'=>'sss', 'id'=>'email', 'class' => 'form-control')) }}
<p>
{{ Form::submit('Submit', array('id'=>'submit','class'=>'btn btn-default' , 'style'=>'float:left')) }}
</p>
</div>
{{ Form::close() }}
注意:您可以移除Input::old()
stuf,因为这是由Form::model()