lundi 15 juillet 2019

how to import CSV file in laravel

Hello to all i am trying to import csv file in my project and i got that error "Call to undefined method Maatwebsite\Excel\Excel::load()" i dont know how to use it so if you know about that pleas tell me something

i am using excel version 3.0 and try to install 2.0.1 but its not working

Here is my code //controller

public function import(Request $request) {

    if ($request->hasFile('imported-file')) {
        $path = $request->file('imported-file')->getRealPath();
        $data = Excel::load($path, function ($reader) {})->get();
        if (!empty($data) && $data->count()) {
            foreach ($data->toArray() as $key => $value) {
                if (!empty($value)) {
                    Item::insert($value);
                    return back();
                }
            }
        }
    }
}

i just want to import my csv file in my project if you know about that pleas tell me



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire