jeudi 3 septembre 2020

checked for multiple checkbox in update form

This is my blade file for the update form. So how I should I retrieve those data in the form by checked the checkbox.

 <div class="form-group row">
                <label class="col-md-3 col-form-label form-control-label" for="input-description">Hobbies</label>
                <div class="col-md-9">
                    <input type="checkbox" name="hobbies[]" class="form-control-label" value="football" > Football
                    &nbsp; <input type="checkbox" name="hobbies[]" class="form-control-label" value="basketball"> Basketball
                     <input type="checkbox" name="hobbies[]" class="form-control-label" value="table_tennis"> Table Tennis
                     <input type="checkbox" name="hobbies[]" class="form-control-label" value="hockey"> Hockey
                     <input type="checkbox" name="hobbies[]" class="form-control-label" value="others"> Others
                </div>
            </div>
 </div>

This is my Controller

public function edit($id)
{
    $student=Student::find($id);
    return view('students.edit', compact('student'));
}

In the database, .hobbies are stored in hobbies column like this

["basketball","football",'table_tennis']


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire