在Laravel中,如果验证失败,它将返回到同一表单页面。如何重新填充复选框以勾选或未勾选?
默认情况下,首次加载页面时应该取消选中。
{{ Form::checkbox('custom_address', false,
Input::old('custom_address'), array('class' => 'test')); }}
答案 0 :(得分:2)
您需要为复选框设置一个值,否则Input
类将始终为空/取消选中。
给复选框一个值1,然后它应该有效。
{{ Form::checkbox('custom_address', 1, Input::old('custom_address'), array('class' => 'test')); }}
答案 1 :(得分:-1)
只需使用条件。
@if(!empty(Input::old('custom_adress')))
{{ Form::checkbox('custom_address', true,
Input::old('custom_address'), array('class' => 'test')); }}
@else
{{ Form::checkbox('custom_address', false,
Input::old('custom_address'), array('class' => 'test')); }}
@endif