Call to undefined method Maatwebsite\Excel\Excel::create() - laravel 5.6
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Solving the Mystery: Call to undefined method Maatwebsite\Excel\Excel::create() in Laravel 5.6
Dealing with cryptic errors when integrating third-party packages can be frustrating, especially when you’ve meticulously followed the documentation. As a senior developer, I often encounter these kinds of issues when working with older Laravel versions and popular packages like Maatwebsite/Excel. The error Call to undefined method Maatwebsite\Excel\Excel::create() strongly suggests that while your package is installed, there is an issue with how the class or facade is being resolved by the framework, often related to service providers or autoloading.
This post will walk you through the likely causes of this specific error when using Maatwebsite/Excel in a Laravel 5.6 environment and provide a robust solution.
Understanding the Error Context
The error message indicates that PHP cannot find the create() method on the Maatwebsite\Excel\Excel class, even though you are attempting to call it via the facade (Excel::create(...)). In modern Laravel applications, this usually points to one of three core problems:
- Missing or Incorrect Service Provider Registration: The package needs to register its functionality with the Laravel container so that facades can resolve correctly.
- Autoloading Issues: PHP cannot locate the necessary class files, often due to Composer setup errors.
- Version Incompatibility: There might be subtle incompatibilities between the specific version of Maatwebsite/Excel and Laravel 5.6 itself.
Let’s examine your configuration provided:
// app.php snippet
'provider' => 'Maatwebsite\Excel\ExcelServiceProvider',
'alias' => 'Excel' => 'Maatwebsite\Excel\Facades\Excel',
While this setup looks correct for facade registration, the problem often lies outside of the main app.php file—specifically in how Composer and Laravel handle class loading.
Step-by-Step Solution
Here is a comprehensive approach to resolving this issue, moving from the simplest checks to more complex dependency fixes.
1. Verify Composer Dependencies
Before diving into Laravel configuration, ensure your dependencies are correctly installed via Composer. A missing or corrupted autoloading can silently cause method resolution failures.
Run the following command in your terminal to ensure all necessary packages are present and properly mapped:
composer dump-autoload
This command regenerates the autoloader files, which often resolves issues where classes are declared but not found by PHP during runtime. If you suspect a dependency conflict, running composer update might be beneficial to pull in any necessary package updates. Remember, keeping your dependencies clean is crucial for maintaining stability in any Laravel project, as advocated by the principles outlined on laravelcompany.com.
2. Re-verify Service Provider Registration
Even though you have registered the provider in app.php, ensure that this file is being loaded correctly. In Laravel 5.6, this registration is fundamental. If you are using a custom setup or running within a specific environment (like a queue worker or Artisan command), make sure your environment setup is consistent.
For package integration, relying on the Service Provider is the correct method to bridge external libraries with the framework. If the error persists after composer dump-autoload, it might indicate an issue where the class itself isn't being loaded properly into the container when the facade tries to access it.
3. Review the Controller Implementation (Best Practice)
Your controller code snippet demonstrates a good use case for exporting data:
Excel::create($fileName, function($excel) use($input,$subjects,$students) {
$excel->sheet('New sheet', function($sheet) use ($input,$subjects,$students) {
$sheet->loadView('app.excel',compact('subjects','input','students'));
});
})->download('xlsx');
This syntax is correct for the package. The issue is almost certainly upstream (autoloader/registration), not in this specific method call itself. However, always ensure you are using the latest recommended approach for file handling if you encounter similar issues.
Conclusion
The error Call to undefined method Maatwebsite\Excel\Excel::create() in a Laravel 5.6 context is typically a symptom of an environment setup issue rather than a bug in the package itself. By strictly following the dependency management steps—specifically running composer dump-autoload and ensuring your service providers are correctly loaded—you should resolve this conflict.
Remember, mastering the ecosystem means understanding how dependencies interact with the core framework. Keep referencing official resources like laravelcompany.com for authoritative guidance on Laravel architecture and package integration. Happy coding!