Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hamzaqureshi16's avatar

Laravel Excel not working with xlsx files

I'm using larave excel to load/import excel files from the frontend(InertiaJS/ReactJS) to my laravel backend. But in my import class I've dd'd the rows but only get null indices. While when I try with a csv file it works fine and I can see the fields in the dd. This is my controller:


    public function importScroll(Request $request): void
    {        
        $file = $request->file('file');
        $file->storeAs('public', $file->getClientOriginalName());
        Excel::import(new ScrollsImport,$file);
    }

this is my import class:

  public function model(array $row)
    {
        dd($row);
        return new BillingScroll([
        ]);
    }
0 likes
1 reply
JussiMannisto's avatar

You shouldn't use getClientOriginalName() to store files in your filesystem. It's considered unsafe as mentioned in the docs.

Laravel does block php and phar file uploads by default nowadays, so object deserialization attacks aren't as easy. But you should still use $file->hashName() and $file->extension() to be on the safe side. And validate the mime types. Don't trust clients.

Please or to participate in this conversation.