我正在使用Maatwebsite Laravel excel将我的excel导入数据库。 我的Excel中有一个日期格式列。导入时,除非值是日期格式,否则将输入数据。如何解决? 日期格式的列为“ tanggal_bergabung”列。
我使用的是Larat 5.8,Maatwebsite 3.1。
<?php
namespace App\Imports;
use App\DatabaseCompany;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
class ImportDatabaseCompany implements ToModel,WithHeadingRow
{
/**
* @param array $row
*
* @return \Illuminate\Database\Eloquent\Model|null
*/
public function model(array $row)
{
return new DatabaseCompany([
//
'kode' => $row['kode'],
'bentuk_perusahaan' => $row['bentuk_perusahaan'],
'company_name' => $row['company_name'],
'kontak_perusahaan' => $row['kontak_perusahaan'],
'grade' => $row['grade'],
'order' => $row['order'],
'industri' => $row['industri'],
'jalan' => $row['jalan'],
'rt' => $row['rt'],
'rw' => $row['rw'],
'kelurahan' => $row['kelurahan'],
'kecamatan' => $row['kecamatan'],
'kabupaten_kota' => $row['kabupaten_kota'],
'provinsi' => $row['provinsi'],
'tanggal_bergabung' => $row['tanggal_bergabung'], //value is datetime
'status' => $row['status'],
'id_sales' => $row['id_sales'],
'sales' => $row['sales'],
'id_captain' => $row['id_captain']
]);
}
}
答案 0 :(得分:1)
要么将其更改为yyyy-mm-dd H:i:s,要么在日期时间输入
\Carbon\Carbon::parse($row['tanggal_bergabung']))