laravel excel import date

Solutions on MaxInterview for laravel excel import date by the best coders in the world

showing results for - "laravel excel import date"
Mae
31 Apr 2017
1// export
2	use PhpOffice\PhpSpreadsheet\Shared\Date;
3
4	public function map($user): array
5	{
6        return [
7            $user->username,
8            Date::stringToExcel($user->deleted_at)
9        ];
10	}
11	public function headings(): array{
12        return [
13            "username",
14            "deleted_at",
15        ];
16	}
17
18// import
19	use PhpOffice\PhpSpreadsheet\Shared\Date;
20
21	public function model(array $row)
22	{
23        if(Date::excelToTimestamp($row["deleted_at"]) != 0){
24            $deleted_at = Date::excelToTimestamp($row["deleted_at"]);
25        }else{
26            $deleted_at = null;
27        }
28
29        return new User([
30            'username' => $row["username"],
31            'deleted_at' => $deleted_at,
32        ]);
33	}
34
35// models
36	protected $fillable = [
37        'username',
38        'deleted_at'
39	];
40