How to fix Call to undefined method Maatwebsite\Excel\Excel::create()?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How to Fix Call to undefined method Maatwebsite\Excel\Excel::create()? A Deep Dive into Laravel Excel Exports

As a senior developer working with the Laravel ecosystem, we frequently encounter errors when dealing with powerful third-party packages. The error you are facing—Call to undefined method Maatwebsite\Excel\Excel::create()—is a classic indicator that the way you are interacting with the maatwebsite/excel package is slightly misaligned with its current implementation or best practices.

This post will diagnose why this happens and provide you with the correct, robust methods for exporting data using Laravel Excel, ensuring your code is clean, functional, and adheres to modern PHP standards.

Understanding the Error: Why Does This Happen?

The error message Call to undefined method means that the object you are calling a method on does not possess that method. In the context of Maatwebsite\Excel\Excel::create(), this usually points to one of three possibilities:

  1. Version Mismatch: You might be using an older version of the package where the static create() method was structured differently, or you are running a newer version where that specific invocation has been deprecated in favor of more object-oriented methods.
  2. Missing Setup/Imports: While less common with modern Composer setups, sometimes missing namespaces or incorrect class loading can trigger this error.
  3. Incorrect Method Usage (The Most Likely Cause): The most significant reason is often attempting to use a static facade method (Excel::create()) when the package prefers an instance-based approach or specialized classes for complex exports.

Laravel, and by extension powerful libraries like those found on platforms like laravelcompany.com, encourage object-oriented programming principles. When dealing with data manipulation and file generation, using dedicated classes often provides clearer structure than relying solely on static facade methods.

The Solution: Adopting the Recommended Export Pattern

Instead of relying on a potentially unstable or outdated static create() method for complex exports, the best practice is to leverage the features provided by Laravel Excel, specifically using Collections and dedicated Export classes.

For your scenario—exporting relationships from Eloquent models—we should focus on preparing the data into a structure that the package expects, typically an array or a Laravel Collection.

Here is the corrected approach for exporting your user data:

Step 1: Prepare Your Data Correctly

First, ensure you are collecting and formatting your data efficiently before passing it to the exporter. We will use Eloquent collections directly.

use Maatwebsite\Excel\Facades\Excel;
use App\Models\User; // Assuming your User model is here

public function exportExcel()
{
    // 1. Fetch the data using Eloquent (Laravel best practice)
    $users = User::all();

    // 2. Prepare the data into a format suitable for the Excel sheet
    // We map the relationships directly to an array of arrays.
    $dataToExport = $users->map(function ($user) {
        return [
            'Name' => $user->name,
            'Email' => $user->email,
        ];
    })->toArray();

    // ... proceed to Step 2
}

Step 2: Use the Correct Export Method

Instead of trying to call a generic Excel::create(), use one of the dedicated export classes provided by the package. The most common and easiest method for simple data exports is using the FromCollection class.

public function exportExcel()
{
    $users = User::all();

    // Prepare data as shown above... (omitted for brevity)
    $dataToExport = $users->map(function ($user) {
        return [
            'Name' => $user->name,
            'Email' => $user->email,
        ];
    })->toArray();


    // Use the FromCollection class to handle the export process cleanly.
    Excel::create(new FromCollection($dataToExport), 'User Data')
        ->setTitle('User Data')
        ->sheet('User Data', $dataToExport) // Pass the prepared data directly here
        ->download('xls');

    return redirect()->route('admin.page');
}

Complete Refactored Example

By restructuring the code to use FromCollection, we eliminate ambiguity and adhere to the intended design of the package, making your export logic much more reliable.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use Maatwebsite\Excel\Concerns\FromCollection; // Import the necessary interface
use App\Models\User;

class ExportController extends Controller
{
    public function exportExcel()
    {
        // Fetch data efficiently
        $users = User::all();

        // Prepare data structure for export
        $dataToExport = $users->map(function ($user) {
            return [
                'Name' => $user->name,
                'Email' => $user->email,
            ];
        })->toArray();

        // Use the correct FromCollection implementation to create the file.
        Excel::create(new FromCollection($dataToExport), 'User Data')
            ->setTitle('User Data')
            ->sheet('User Data', $dataToExport)
            ->download('xls');

        return redirect()->route('admin.page');
    }
}

Conclusion

The error Call to undefined method Maatwebsite\Excel\Excel::create() is a symptom of calling a method that doesn't exist in the current package version or an incorrect usage pattern. As developers, our goal should always be to follow the documented, idiomatic way of using a library. By switching from attempting a generic facade call to utilizing specific export classes like FromCollection, you ensure your code is robust, readable, and compatible with future updates. Always consult the official documentation for the latest methods when working with powerful tools from the Laravel ecosystem.