You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Good afternoon everyone, I need to make an insert in 2 tables: "serialziacions" and "det_serializacions" for what in my controller I have a function that through a transaction will make the insert, but in the table "det_serializacions" data must be inserted from an excel file that is loaded from a form in a modal window (where are the additional data to be inserted).
I have this function in my controller but it doesn't work, I don't know how to do the insert in the second table (the excel and the additional data):
public function store(Request $request)
{
//$path = $request->file('serie')->getRealPath();
//$data = Excel::import(new DetSerializacionImport, $path);
//dd($data);
//return $data;
try {
DB::beginTransaction();
//INSERT A LA TABLA PADRE "SERIALIZACIONS"
$serializacion = new Serializacion();
$serializacion->fecha_serializacion = $request->get('fecha_serializacion');
$serializacion->status = $request->get('status');
$serializacion->usuario_id = $request->get('usuario_id');
$serializacion->ingreso_material_id = $request->get('ingreso_material_id');
$serializacion->det_ingreso_material_id = $request->get('det_ingreso_material_id');
$serializacion->save();
//INSERCION A LA TABLA MENOR "DET_SERIALIZACIONS" INCLUYENDO DATOS DEL EXCEL
//LOS DATOS A INSERTAR VIENEN DESDE LA VENTANA MODAL
$path = $request->file('serie')->getRealPath();
Excel::import(new DetSerializacionImport, $path, function($reader) {
$serie = $reader->get();
$reader->each(function($row, $request, $serializacion) {
$material_id = $request->get('material_id');
$detalleSeriado = new DetSerializacion;
$detalleSeriado->mac = $row->mac; //ESTE DATO VIENE DEL EXCEL
$detalleSeriado->serie = $row->serie; //ESTE DATO VIENE DEL EXCEL
$detalleSeriado->serializacion_id = $serializacion->id; //ID GENERADO EN EL PRIMER INSERT
$detalleSeriado->material_id = $material_id;
//$user->save();
$detalleSeriado->save();
//$cont=$cont+1;
});
});
DB::commit();
} catch (\Exception $e) {
//throw $th;
DB::rollback();
}
//return ('hola');
}
And the code of the modal (where the excel is loaded and where are the additional data for the insert in the second table):
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Good afternoon everyone, I need to make an insert in 2 tables: "serialziacions" and "det_serializacions" for what in my controller I have a function that through a transaction will make the insert, but in the table "det_serializacions" data must be inserted from an excel file that is loaded from a form in a modal window (where are the additional data to be inserted).
I have this function in my controller but it doesn't work, I don't know how to do the insert in the second table (the excel and the additional data):
And the code of the modal (where the excel is loaded and where are the additional data for the insert in the second table):
Thank you very much for your attention and help, from Chile...
Beta Was this translation helpful? Give feedback.
All reactions