Search code examples
laravellaravel-5eloquentlaravel-excel

How to save the csv when i import it in Laravel


i am new in Laravel, and i have an import list page (this page work very good), this import some list to put on database. But i want to save this list too.

Heres my code (CsvImport.php):

<?php

namespace App\Imports;

use App\Product;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Illuminate\Support\Facades\Auth;

class CsvImport implements ToModel, WithHeadingRow
{
    public function model(array $row)
    {
        return Product::query()->forceCreate([
            'name'        => $row["name"],
            'description' => $row["description"],
            'category'    => $row["category"],
            'price'       => $row["price"],
            'image'       => 'no-image.jpg',
            'user_id'     =>  Auth::user()->id,
        ]);
    }
}

Some Ideas? :)


Solution

  • i did not find, but i think is better not save.