Laravel Excel Import pathinfo() expects parameter 1 to be string, object given

Viewed 17

I'm using LaravelExcel and I want to load an Excel file on my project from a form, so I tried this:

use Maatwebsite\Excel\Facades\Excel;

public function postDocuments(Request $request)
{
    try {
         Excel::import($request->file('student_list'), function ($reader) {
                foreach ($reader->toArray() as $row) {
                     dd($row);
                }
         });
    } catch (\Exception $e) {
         dd($e);
    }
}

But I get this error when uploading:

pathinfo() expects parameter 1 to be string, object given

enter image description here

So what's going wrong here?

How can I solve this issue?

1 Answers

Import static method looks like this:

import(object $import, string|UploadedFile $filePath, string $disk = null, string $readerType = null)

As you can see, first parameter import class and second parameter is file or path.

If you use latest version, in my opinion in case your code is wrong.

Maybe this page is helpful for this issue => https://docs.laravel-excel.com/3.1/imports/basics.html

Related