Insert multiple data in database in laravel

-1

I need to save in an array the text strings I have in several inputs that have been created dynamically, to send them to the controller and that it can insert them in the database.

// This would be the view

 //ESTO ES EL CODIGO QUE GENERA LOS BOTONES DE AÑADIR Y BORRAR LOS INPUTS DINAMICOS
 <script type="text/javascript">

icremento=0;  

function crear(obj) { 

    icremento++;  
    field = document.getElementById('field');  
    contenedor = document.createElement('div');  
    contenedor.id = 'div'+icremento;  
    field.appendChild(contenedor);  

    boton = document.createElement('input');    
    boton.type = 'text';  
    boton.name = 'text'+icremento;  
    contenedor.appendChild(boton);  

    boton = document.createElement('input');  
    boton.type = 'button';  
    boton.value = 'Borrar';  
    boton.name = 'div'+icremento;  
    boton.onclick = function () {borrar(this.name)}  
    contenedor.appendChild(boton);  
}

function borrar(obj) {  
    field = document.getElementById('field');  
    field.removeChild(document.getElementById(obj));  
}  

</script>  
 <input type="button" value="Crear caja de texto" onclick="crear(this)"  class="btn btn-info"><br><br>  

// THIS WOULD BE THE CONTROLLER

    public function store(Request $request){  
        $date = Carbon::now();  
        $fecha = $date->format('d-m-Y');  
        $localizacion = $request->selector; //recibe informacion de un combobox
    $observaciones = $request->comentarios; //recibe informacion de un 
    textarea

    $tarea = new Tarea();
    $tarea->fecha=$fecha;
    $tarea->zona=$localizacion;
    $tarea->observaciones=$observaciones;

    $tarea->actividades="Y por qui pasaria el array de los datos de los inputs dinamicos";
    $tarea->save();
    return redirect('home');
}
    
asked by Angel Calderón 27.10.2017 в 13:13
source

1 answer

0

For this problem, you have to place at the end of the name the following keys [] so that all the inputs with that name The same can be handled as a array in PHP .

Try it and tell us how it went.

    
answered by 30.10.2017 / 18:17
source