0

I am trying to upload csv and import csv data to database it works fine, but I am facing issue with the integer field in the database.

My csv file have product name and quantity field

Excel::filter('chunk')->load($uploaded_file)->chunk(100, function($results) {
    foreach($results as $result) {
        echo $result->quantity;     # When I try to insert it is 0 because it is string
        # I tried typecasting (int)$result->quantity; it leads to 0
        # And also intval($result->quantity); this too leads to 0
    }
});

This is the package I am using

Prabhakaran
  • 3,900
  • 15
  • 46
  • 113

1 Answers1

1

$xls_datas = Excel::load($xlsFile, function($reader) { })->toArray();

//$csv_values = $this->readCSV($csvFile);           
//$except_first_row_excel = array_slice($csv_values, 1, -1);
//$total_excel_rows = $except_first_row_excel-1;

if(count($xls_datas) > 0)
{
    foreach($xls_datas as $xls_data)
    {
      $xls_data->quantity;//insert query
    }
}
Boopathi N
  • 46
  • 2