Laravel 在控制器内使用 Excel 包

2 laravel laravel-5

我尝试Excel: @package maatwebsite/excel在控制器内的 laravel 上使用包,但出现此错误:

Non-static method Maatwebsite\Excel\Excel::create() 
should not be called statically, assuming $this from incompatible context
Run Code Online (Sandbox Code Playgroud)

我的路线是:

Route::get('all_users_report/{format}', 'SystemExportDataController@all_users_report');
Run Code Online (Sandbox Code Playgroud)

我的控制器是:

class SystemExportDataController extends Controller
{
    /**
     * @param $format
     */
    public function all_users_report($format)
    {
        Excel::create('all_users_records', function ($excel) use ($format) {
            $excel->sheet('My Site - all users report', function ($sheet) use ($format) {
                ........
            });
        })->export($format);
    }
}
Run Code Online (Sandbox Code Playgroud)

帖子已更新 2

'providers' => [
    ...
    'Maatwebsite\Excel\ExcelServiceProvider'
],
'aliases' => [
    ...
    'Excel'     => 'Maatwebsite\Excel\Facades\Excel'
],
Run Code Online (Sandbox Code Playgroud)

错误:

BadMethodCallException in ServiceProvider.php line 234: 
Call to undefined method [package]
Run Code Online (Sandbox Code Playgroud)

更新3:

全类控制器:

<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use Maatwebsite\Excel\Excel;

class SystemExportDataController extends Controller
{
    public function all_users_report($format)
    {
        Excel::create('all_users_records', function ($excel) use ($format) {
            $excel->sheet('Epay.Li - all users report', function ($sheet) use ($format) {
                $all_records = ChangeMoney::all();
                $sheet->loadView('layouts.admin.all_users_report',
                    array(
                        'all_records' => $all_records,
                    )
                );
            });
        })->export($format);
    }
}
Run Code Online (Sandbox Code Playgroud)

Hem*_*ant 8

当您调用静态方法时,请use Maatwebsite\Excel\Facades\Excel不要使用use Maatwebsite\Excel\Excel;Excel::create()