mardi 9 juin 2020

Undefined index: name (Import list) Laravel

i am doing a project using Laravel, and I trying make an import list (csv), like in this video: https://www.youtube.com/watch?v=PrjuwU-Xu7A&t=243s

I think, it is almost done the import list page; but keep giving this error: Undefined index: name

Probably the problem is here:

CsvImport.php:

<?php

namespace App\Imports;

use App\Product;
use Maatwebsite\Excel\Concerns\ToModel;

class CsvImport implements ToModel
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new product([
            'name'          => $row["name"],
            'description'   => $row["description"],
            'category'      => $row["category"],
            'price'         => $row["price"],
            'user_id'       => $row["user_id"],


        ]);
    }
}

web.php

Route::get('/csv_file', 'CsvFile@index');

Route::post('csv_file/import', 'CsvFile@csv_import')->name('import');

My database (table) call product. I am following exactly the video. Please help me.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3hc0xvs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire