<?php

namespace App\Imports;

use App\Models\Data;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class DataImport implements ToModel, WithHeadingRow
{
    /**
     * @param array $row
     *
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function model(array $row)
    {
        return new Data([

            'dateOfPurchase' => \Carbon\Carbon::parse($row['dateofpurchase'])->format('Y-m-d'),
            'name' => $row['name'],
            'user' => $row['user'],
            'idSecond' => $row['id'],
            'type' => $row['type'],
        ]);
    }
}
