簡體   English   中英

laravel上傳csv並將csv文件數據導入具有整數字段的數據庫

[英]laravel upload csv and import csv file data to database with integer field

我正在嘗試上載csv並將csv數據導入數據庫,它工作正常,但是我面臨數據庫中整數字段的問題。

我的csv文件包含產品名稱數量字段

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
    }
});

這是我正在使用的包

$ 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
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM