I want to save a request and at the same time with the same ID save the detail that of articles that come with it.
public function store(Request $request){
$this->solicitud->save();
foreach ($request->descripcion as $data ) {
$detalle = new Detalle();
$detalle->cantidad = Input::get('cantidad');
$detalle->descripcion = Input::get('descripcion');
$this->solicitud->detalles()->save($detalle);
}}
Detail model
protected $fillable=[ 'cantidad','descripcion','solicitud_id'];
public function something()
{
return $this->belongsTo(Solicitud::class, 'solicitud_id');
}
Request Model
protected $fillable=['titulo','fundamento','estado','slug','departamento_id','user_id'];
public function detalles()
{
return $this->hasMany(Detalle::class, 'solicitud_id');
}
}
<html>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<table class="table table-bordered" id="dynamic_field">
<thead>
<tr>
<th style="width:50px" scope="col">Cantidad</th>
<th scope="col">Descripcion</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="cantidad[]" placeholder="Cantidad" class="form-control name_list" /></td>
<td><input type="text" name="descripcion[]" placeholder="Descripcion" class="form-control name_list" /></td>
<td><button type="button" name="add" id="add" class="btn btn-success">Agregar + </button></td>
</tr>
</tbody>
</table>
<script
src="http://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
var i=1;
$('#add').click(function(){
i++;
$('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text"name="cantidad[]" placeholder="Cantidad" class="form-control name_list" /><td><input type="text"name="descripcion[]" placeholder="Descripcion" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">Quitar</button></td></tr>');
});
$(document).on('click', '.btn_remove', function(){
var button_id = $(this).attr("id");
$('#row'+button_id+'').remove();
});
});
</script>
</html>
I miss this error
Type error: Argument 1 passed to Illuminate \ Database \ Grammar :: parameterize () must be of the type array, integer given, called in C: \ xampp \ htdocs \ project \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Query \ Grammars \ Grammar.php online 681
I hope I could have explained myself well. Greetings