Laravel Excel cannot update records "WithUpserts" - error update

Viewed 12

I face various issues while updating my existing table. I need to update the price field in my table, but I get an error in my code that I can't find. Even if I remove the sku it goes to the next "qty" field and outputs undefined. "Undefined index: sku"

<?php

namespace App\Imports;

use App\Models\CatalogStore;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithUpserts;

class CatalogupdateImport implements ToModel, WithUpserts
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new CatalogStore([
        'sku' => $row['sku'],
        'price' => $row['price'],
        'qty' => $row['qty'],
        ]);
    }

    /**
    * @return string|array
    */
    public function uniqueBy()
    {
        return 'price';
    }

}
0 Answers
Related