Non-static method Maatwebsite\Excel\Excel::create() should not be called statically, assuming $this from incompatible context.
I am trying to call the create and load methods from a controller. as shown in the documentation. However all I can get is an error stating that this method cannot be called statically.
I am using version 2.0.4, running on Laravel 5.
Whenever you see a static call (like ::create()), this indicates the use of the facade.
You can alias the facade in config/app.php : 'Excel' => 'Maatwebsite\Excel\Facades\Excel',
Now inside your controller you have to import it in top of the class like so:
<?php
use Excel;
class YourController {
public function yourMethod()
{
Excel::create();
}
}
It was already in there, for some reason just tabbing the operator fixed it.. strange.
Thank you!
i have same problem and it fixed with:
use Excel;
Non-static method Maatwebsite\Excel\Excel::create() should not be called statically, assuming $this from incompatible context
You need to use the facade if you want to call create() statically: Maatwebsite\Excel\Facades\Excel
There is a "conflict" when using the Facade and using class constants.
Maatwebsite\Excel\Excel::XLSX
Maatwebsite\Excel\Facades\Excel
And I quote "conflict" since I know that thats what namespaces are for, but its badly documented, counter-intuitive and "breaks the flow".
Most helpful comment
Whenever you see a static call (like
::create()), this indicates the use of the facade.You can alias the facade in
config/app.php:'Excel' => 'Maatwebsite\Excel\Facades\Excel',Now inside your controller you have to import it in top of the class like so: