Flag form binding form

I am using Laravel 4.1, and in my application I need to show a form with pre-filled checkboxes. But I'm trying to do this with Form Model Binding, this will not 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 work?

+4
source share
2 answers

Works well for me, here is the 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'));

});

Here is what I got:

<input checked="checked" name="notify_rate" type="checkbox" value="1">
<input name="notify_rate" type="checkbox" value="1">
+2
source

, , @Ladislav Maxa @Antonio Carlos Ribeiro, . , , "unchecked".

, , - get. , .

$notify_rate = Input::get('notify_rate') ? 1 : 0;
$data['notify_rate'] = $notify_rate;

, , 0 . , , , .

<input name="notify_rate" type="text" value="0">
<input name="notify_rate" type="checkbox" value="1">

, HTML, .

+6

Source: https://habr.com/ru/post/1535031/


All Articles