php - Save multiple checkbox - Laravel 5.4 -


i need save multiple checkbox single field in 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 trying save, values ​​in [""], need save numbers

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

when try save, show next message

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

you'r cannot add because can try loop expresion_vegetal_id still in array format. see in question need add in string format. must loop array first , save 1 one or can used created

i give sample using loop. code looks this

$ficha_tecnica = new ficha_tecnica(); foreach ($$request->expresion_vegetal_id $expresion_vegetal_id) {     $ficha_tecnica->fresh();     $ficha_tecnica->expresion_vegetal_id = $expresion_vegetal_id;     $ficha_tecnica->save(); } 

i hope can find other same way....


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -