Home > other >  Maatwebsite Laravel Excel import empty values
Maatwebsite Laravel Excel import empty values

Time:02-10

Hi there I'm trying to do an excel import with https://docs.laravel-excel.com/3.1/imports/basics.html I'm able to do it with two rows, but when I tried with more I'm getting this message error:

"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tipo_comprobante' cannot be null (SQL: insert into ingresos (idproveedor, idusuario, tipo_comprobante, serie_comprobante, num_comprobante, fecha_hora, impuesto, total, estado, updated_at, created_at) values (7, 1, , , , 2022-02-09 21:13:27, , , , 2022-02-09 22:13:27, 2022-02-09 22:13:27))"

Like my values are empty, I did add to check the values on $row coming from the excel, and I'm able to see data:

[
  "contacto" => "Daniela Chamuco"
  "comprobante" => "Factura"
  "serie" => "0001"
  "num_comprobante" => "000004"
  "impuesto" => 0.16 "total" => 240 "estado" => "Registrado"
]

This is my IngresosImport

private $proveedores;

public function __construct()
{
    //$this->proveedores = Proveedor::select('id', 'contacto', 'telefono_contacto')->get();
    $this->proveedores = DB::table('proveedores')->get();
}

use importable;
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
    $proveedor = $this->proveedores->where('contacto',$row['contacto'])->first();
    //dd($row);
    return new Ingreso([
    // 'idproveedor'  => $proveedor->id ?? NULL,
    'idproveedor'  => 7,
    'idusuario' => Auth::user()->id,
    'tipo_comprobante' => $row['comprobante'],
    'serie_comprobante' => $row['serie'],
    'num_comprobante' => $row['num_comprobante'],
    'fecha_hora' => Carbon::now('America/Mexico_city'),
    'impuesto' => $row['impuesto'],
    'total' => $row['total'],
    'estado' => $row['estado'],
    ]);
}

IngresosController

public function import(Request $request){

    $request->validate([
        'file' => 'required|file|mimes:xls,xlsx'
    ]);

    $path = $request->file('file');
    
    $data = Excel::import(new IngresosImport, $path);
        
    return response()->json(['message' => 'uploaded successfully'], 200);
}

Any idea how I can do the import or what I am doing wrong? Thanks in advance...

CodePudding user response:

  •  Tags:  
  • Related