Answers for "laravel excel import date"

PHP
0

laravel excel import date

// export
	use PhpOffice\PhpSpreadsheet\Shared\Date;

	public function map($user): array
	{
        return [
            $user->username,
            Date::stringToExcel($user->deleted_at)
        ];
	}
	public function headings(): array{
        return [
            "username",
            "deleted_at",
        ];
	}

// import
	use PhpOffice\PhpSpreadsheet\Shared\Date;

	public function model(array $row)
	{
        if(Date::excelToTimestamp($row["deleted_at"]) != 0){
            $deleted_at = Date::excelToTimestamp($row["deleted_at"]);
        }else{
            $deleted_at = null;
        }

        return new User([
            'username' => $row["username"],
            'deleted_at' => $deleted_at,
        ]);
	}

// models
	protected $fillable = [
        'username',
        'deleted_at'
	];
Posted by: Guest on October-05-2021

Browse Popular Code Answers by Language