Laravel-excel: Non-static methods should not be called from a static context

Created on 19 May 2015  路  6Comments  路  Source: Maatwebsite/Laravel-Excel

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.

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:

<?php

use Excel;

class YourController {

    public function yourMethod()
    {
        Excel::create();
    }

}

All 6 comments

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".

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthewslouismarie picture matthewslouismarie  路  3Comments

kurianic picture kurianic  路  3Comments

muhghazaliakbar picture muhghazaliakbar  路  3Comments

contifico picture contifico  路  3Comments

lucatamtam picture lucatamtam  路  3Comments