jeudi 11 juin 2020

How to save the csv when i import him? (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? :)



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

Aucun commentaire:

Enregistrer un commentaire