lundi 11 septembre 2017

Save multiple checkbox - Laravel 5.4

I need to save multiple checkbox to single field in the database.

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="expresion_vegetal_id[]" value="1">Raíz
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="expresion_vegetal_id[]" value="3">tronco
                </label>
            </div>
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="expresion_vegetal_id[]" value="4">corteza
                </label>
            </div>

Controller:

$ficha_tecnica = new Ficha_Tecnica();
$options = $request->get('expresion_vegetal_id');
$ficha_tecnica->expresion_vegetal_id = $options;
$ficha_tecnica->save();

this is trying to save, the values ​​in [""], I need only save the numbers

insert into `fichas_tecnicas` (`expresion_vegetal_id`) values (["1","3","4"])

When I try to save, show the next message

1366 Incorrect integer value: '["1","4"]' for column 'expresion_vegetal_id' 

Aucun commentaire:

Enregistrer un commentaire