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

khaledalsamman's avatar

Call to a member function store() on null

so, i am using laravel 8 to import an excel file into my db and from there display the data. its my first time dealing with any file upload in laravel an di am really lost.

here is my form :

<form class="formCus" method="post" action="/import"  enctype="multipart/fomr-data" >
     
      {{ csrf_field() }} 
      <label class="formItem" for="fileUpload">Upload your excel file: </label>     
      <input class="formItem" type="file" name="excelFile" id="file" >

      <button class="formItem" type="submit">Upload File</button>

    </div>

and my Controller:

<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use App\Models\Employees;
use Maatwebsite\Excel\facades\Excel;
use App\Imports\EmployeesImport;


class EmployeeController extends Controller
{
    
    public function index(){
        
        $employees = new Employees;
        
        return view('welcome');

    }

    public function import(Request $req){

        $req->validate([
            'excelFile' => 'required'
        ]);

        $path1 = $req->file('excelFile')->store('/','public');

        $path=storage_path('app').'/'.$path1;  

        Excel::import(new EmployeesImport, $path);
        
        return view('welcome');

    }

    public function export(){
        dd("Export");
    }

}
0 likes
3 replies
khaledalsamman's avatar

Thanks i would have never noticed that haha. however the problem is still unsolved.

I verified my file which is giving me a new problem now. using this

' ' '

    $req->validate([
        'excelFile' => 'required|mimes:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    ]);

    $path1 = $req->file('excelFile')->store('/','public');
    
    $path=storage_path('app').'/'.$path1;  

    $data =  Excel::import(new EmployeesImport, $path);
    
    return view('imported');
}

' ' '

I am uploading a .csv file which is being invalid i think so i am going back to my main view " welcome"

I have also tried this :

$req->validate([ 'excelFile' => 'required|mimes:mimes:xlsx, csv, xls', ]);

neilstee's avatar

@khaledalsamman I think that is not part of the actual question here which is Call to a member function store() on null.

I suggest closing this thread by marking a reply that solves your issue as Best Answer and post a new thread with your new error regarding validation 😉

Please or to participate in this conversation.