<?php

namespace App\Imports;
use App\Model\product\ColorModel;
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Validators\Failure;
use Maatwebsite\Excel\Concerns\WithCalculatedFormulas;

class ColorImport implements ToModel, WithHeadingRow, SkipsOnFailure, WithCalculatedFormulas
{

    public function model(array $row)
    {

        if (@$row['code']) {
            $check = findColor($row['code']);
            if(!$check){
                $arr = [ 'code' => $row['code'],'name' => $row['name']];
                return ColorModel::updateOrCreate($arr,$arr );
            }
        }
    }

    public function onFailure(Failure ...$failures)
    {
        // TODO: Implement onFailure() method.
    }
}
