jeudi 12 octobre 2017

In Laravel 5.4 I need to check a checkbox if it was checked on a previous save

I cant for the life of me work out what I need to do to get my checkbox to display checked if I previously checked it on my one database entry.

My database has a field called languages. In it I store the languages that users are fluent in. I do this with them filling out a form that includes a lot of checkboxes. This is what my form looks like:

                            <label class="checkbox-inline">
                                <input type="checkbox" id="inlineCheckbox" name="languages[]" value="English"> English
                            </label><br/>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="inlineCheckbox" name="languages[]" value="Finnish"> Finnish
                            </label><br/>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="inlineCheckbox" name="languages[]" value="French"> French
                            </label><br/>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="inlineCheckbox" name="languages[]" value="German"> German
                            </label><br/>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="inlineCheckbox" name="languages[]" value="Italian"> Italian
                            </label><br/>
                            <label class="checkbox-inline">
                                <input type="checkbox" id="inlineCheckbox" name="languages[]" value="Portugese"> Portugese
                            </label><br/>

Then when I save it to the database, it saves like this:

["English", "Portugese"]

I have made an edit page, but how do I mark for example, English and Portguese as checked when I open the edit form?

The MySQL table column is a JSON column. Any help would be appreciated



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire