lundi 7 août 2017

Unable to access values from multiple html checkboxes

I am trying to save the values from html checkboxes in a MySQL database table but I am not doing it right. I need your suggestions here.

This is my html

@foreach($sql as $sql)
<div class="form-group">
    <label class="control-label mb-10" for=""></label>
    <div class="input-group">
        <input type="hidden" name="resource[]" value="">
        <input type="checkbox" name="resources[]" value="c">Create
        <input type="checkbox" name="resources[]" value="r">Read
        <input type="checkbox" name="resources[]" value="u">Update
        <input type="checkbox" name="resources[]" value="d">Delete
    </div>
</div>
@endforeach

This is my controller where I am trying to save into a DB table

    public function store(Request $request){
    foreach ($request->resource as $resource) {
                        # code...
                        foreach ($request->resources as $resources) {
                            $res[] = $resources;
                            $options =  implode(',', $res); //Get selected options
                            $resource = $resource; //Get value of the resource

                        }
                    }
}

This does not work as it only shows just one 'selected checkbox field'. Please what am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire