HimanshuSamantaray
HimanshuSamantaray

Reputation: 93

How to dynamically populate checkbox from database

I want to populate the view.blade.php page with the value given in add.blade.php. I am getting my form values using a variable $form_value from the database. How can I use this variable to populate the chekbox in view page.

view.blade.php

<div class = "row">
        <div class="col-lg-4">
            <label>
              <input type="checkbox" name="hoogwerker"><b> Hoogwerker gebruikt</b>
            </label>
        </div>
        <div class="col-lg-4">
            <label>
              <input type="checkbox" name="koerier"><b> Materiaal toegeleverd via koerier</b>
            </label>
        </div>
        <div class="col-lg-4">
            <label>
              <input type="checkbox" name="bijgewerkt"><b> Kraanboek bijgewerkt</b>
            </label>
        </div>
    </div>

add.blade.php

<div class = "row">
                <div class="col-lg-4">
                    <label>
                      <input type="checkbox" name="hoogwerker"> Hoogwerker gebruikt
                    </label>
                </div>
                <div class="col-lg-4">
                    <label>
                      <input type="checkbox" name="koerier"> Materiaal toegeleverd via koerier
                    </label>
                </div>
                <div class="col-lg-4">
                    <label>
                      <input type="checkbox" name="bijgewerkt"> Kraanboek bijgewerkt
                    </label>
                </div>
            </div>

Upvotes: 0

Views: 1451

Answers (1)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

Laravel will do it automatically for you if your blade template is done using Form::model():

{{ Form::model($model) }}

    {{ Form::checkbox('hoogwerker') }}
    {{ Form::label('hoogwerker', 'Hoogwerker gebruikt') }}

    {{ Form::checkbox('koerier') }}
    {{ Form::label('koerier', 'Materiaal toegeleverd via koerier') }}

{{ Form::close() }}

And your controller should do something like

$model = User::find(1);
return View::make('your-view')->with('model', $model);

Upvotes: 2

Related Questions