Call to undefined method Maatwebsite\Excel\Excel::load()

Call to undefined method Maatwebsite\Excel\Excel::load()

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Call to undefined method Maatwebsite\Excel\Excel::load()

You are encountering this error because you are using a syntax pattern that no longer exists in Maatwebsite/Laravel-Excel version 3.0 and later. The Excel facade was completely redesigned in the 3.x release cycle, moving away from static methods like load() toward a fluent interface builder pattern. When you invoke Excel::load(), Laravel cannot find that method on the facade object, resulting in the "Call to undefined method" exception.

To resolve this, you need to refactor your controller logic to use the new import() or read() methods provided by the package. The approach depends entirely on whether you are processing a file from the filesystem (which is what you are currently attempting) or reading directly from an uploaded stream.

Handling Filesystem Imports

In your current implementation, you extract the real path of the uploaded file and pass it to the loader. In version 3.x, if you intend to read from a specific file path on the server, you must use the Excel::import() method instead. This method accepts an import class (or a closure in some configurations) as its primary argument.

Here is how your controller logic should look after updating for compatibility:

use Maatwebsite\Excel\Facades\Excel;
use App\Models\Employee; // Assuming this is your model

public function importsave(Request $request)
{
    if ($request->hasFile('excel')) {
        $path = $request->file('excel')->getRealPath();
        
        // Use 'import' instead of 'load', passing a closure that defines the Import class
        $collection = Excel::import(new EmployeeImport, $path);

        // The import method returns a Collection containing the imported rows
        if (!empty($collection) && $collection->count()) {
            foreach ($collection as $value) {
                // Ensure you handle potential nulls or empty arrays correctly here
                if (!empty($value)) {
                    Employee::insert($value);
                }
            }
        }
    }
}

However, there is a critical architectural consideration regarding how you define your import logic. In the modern version of the package, the standard practice involves creating a dedicated class that extends Maatwebsite\Excel\Imports\Importer. You cannot simply pass an empty closure to import() and expect it to function without defining the mapping rules inside a specific class.

The Import Class Requirement

Instead of relying on the anonymous closure syntax from older versions, you should create a new file in your application directory, for example at app/Imports/EmployeeImport.php. This file needs to extend the base importer and define the columns that map to your database model.

namespace App\Imports;

use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use App\Models\Employee;

class EmployeeImport implements ToModel, WithHeadingRow
{
    /**
     * @param array $row
     *
     * @return \Illuminate\Database\Eloquent\Model|null
     */
    public function model(array $row)
    {
        // Return a new instance of the Employee model populated with row data
        return new Employee($row);
    }
}

Once this class exists, you can simplify your controller further. You no longer need to manually instantiate the collection or check for emptiness in the way previous code suggested; the import process will handle the reading and returning of rows automatically. If you prefer injecting the import logic directly into the command, you can pass the closure to define the model mapping inline:

$collection = Excel::import(function($reader) {
    return new EmployeeImport(); // Instantiate your custom importer here
}, $path);

Stream vs. Path Handling

If you were previously using Excel::load() expecting it to handle the stream directly, note that the newer API distinguishes between file paths and streams more explicitly. If you have not called getRealPath(), you might consider passing the uploaded resource directly if your import class supports reading from streams, though checking for a valid path is often safer for batch processing operations involving multiple files.

Always ensure your Employee model casts the incoming attributes correctly, or update the mapping in your ToModel implementation to handle data types (e.g., converting strings to dates) before insertion. The shift from load() to import() is not just a syntax change; it reflects a deeper separation of concerns where the import logic lives in its own class rather than being tightly coupled inside a controller closure.

For further guidance on handling specific Excel configurations or advanced mapping strategies, you may want to review resources such as https://laravelcompany.com which often covers nuances in integrating third-party packages with modern Laravel versions.

Our network