复选框的表单模型绑定 [英] Form Model Binding for checkboxes
本文介绍了复选框的表单模型绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Laravel 4.1,在我的应用中,我需要显示一个带有预填充复选框的表单.但是我尝试使用表单模型绑定"来做到这一点,这是行不通的.
I'm using Laravel 4.1 and in my app I need to show a form with pre filled checkboxes. But I try to do it with using Form Model Binding, it doesn't work.
{{ Form::model($user, array('route' => 'settings-notify')) }}
<div class="formRow form-horizontal_row">
{{ Form::checkbox('notify_visit', '1') }}
</div>
<div class="formRow form-horizontal_row">
{{ Form::checkbox('notify_rate', '1') }}
</div>
<div class="formSubmit">
{{ Form::submit('Save') }}
</div>
{{ Form::close() }}
有什么方法可以使其正常工作吗?
Is there any way to make it working?
推荐答案
对我来说很好,这是我刚刚在这里做的测试:
Works fine for me, here's a test I just did here:
Route::get('test', function() {
$user = User::where('email','myemail@domain.com')->first();
Form::model($user);
$user->notify_rate = true;
echo e(Form::checkbox('notify_rate'));
$user->notify_rate = false;
echo e(Form::checkbox('notify_rate'));
});
这就是我得到的:
<input checked="checked" name="notify_rate" type="checkbox" value="1">
<input name="notify_rate" type="checkbox" value="1">
这篇关于复选框的表单模型绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文