0

Me da este error en Laravel al querer importar un documento excel a mi base de datos en mysql el código es el siguiente:

 public function store(ImportadorMarceloRequest $request)
    {
        //
        $path = $request->file('archivo')->storeAs('uploads/importaciones', $request->file('archivo')->getClientOriginalName(), 'web');
        $filePath = public_path() .'/'.$path;
        Excel::load($filePath, function($reader) use ($request){
            $objExcel = $reader->getExcel();
            $sheet = $objExcel->getSheet(0);

            DB::transaction(function(){
                foreach ($sheet->toArray() as $key => $row) {
                    if ($key >= 3) {
                        try {
                            $inmueble = Inmueble::where('id_unico', $row[1])
                                            ->where('promocion', $row[2])
                                            ->where('id_prinex', $row[3])->first();

                            if ($inmueble == null) {
                                $inmueble = new Inmueble();
                            }
                            $inmueble->fecha_datos = empty(trim($row[0])) ? null : $row[0];
                            $inmueble->id_unico = empty(trim($row[1])) ? null : $row[1];
0

1 respuesta 1

1

La función anónima dentro de DB::transaccion debiera incluir un use ($sheet). Un closure no tiene acceso a las variables definidas afuera

$sheet = $objExcel->getSheet(0);
DB::transaction(function() use ($sheet) {
 ...
});
1

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.