jeudi 11 juin 2020

Assign a value to a database column from form data while importing using Laravel maatwebsite Laravel Excel

I am trying to import excel file to database using Laravel Excel. My import file is:

<?php

namespace App\Imports;

use App\Model;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\ToModel;

class ModelsImport implements ToModel
{
    use Importable;
    public function model(array $row)
    {
        return new Model([
            'model_id' => ??           
            'a' => $row[0],
            'b' => $row[1],
            'c' => $row[2],
            'd' => $row[3],             
        ]);
    }
}

My controller:

public function uploadExcel(){
        (new ModelsImport)->import(\request()->file('excel'),'local',\Maatwebsite\Excel\Excel::XLSX);
        return redirect()->back();
    }

I want to assign model_id a value from the submitted form. How can I do that? I already have the form that gives me model_id when I submit it.



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

Aucun commentaire:

Enregistrer un commentaire