Lumen 通过 Composer 引入 maatwebsite/Excel 时出现问题,求解决?

Target [Illuminate\Contracts\Routing\ResponseFactory] is not instantiable while building [App\Http\Controllers\SingleTenant\OrgAdmin\FragmentExportController].

已经再lumen项目里config/app.php引入如下

'providers' => [
    /*
     * Package Service Providers...
     */
    Maatwebsite\Excel\ExcelServiceProvider::class,
]
'aliases' => [
    ...
    'Excel' => Maatwebsite\Excel\Facades\Excel::class,
]

bootstrap\app.php加入

$app->register(Maatwebsite\Excel\ExcelServiceProvider::class);

在config文件夹内手动拷入excel.php

<?php

use Maatwebsite\Excel\Excel;

return [
    'exports'            => [

       .
       .
       .
        */
        'chunk_size' => 1000,
        .
        .
        .

并在bootstrap/app.php加入

$app->configure('excel');

我的代码

namespace App\Http\Controllers\SingleTenant\OrgAdmin;

use App\Modules\Cms\ExportService;
use Maatwebsite\Excel\Excel;
class FragmentExportController
{
    private $excel;

    public function __construct(Excel $excel)
    {
        $this->excel = $excel;
    }

    public function export()
    {
//        return Excel::download(new ExportService, 'error_code.xlsx');
        return $this->excel->download(new ExportService, 'error_code.xlsx');
    }
}
namespace App\Modules\Cms;

use App\Modules\Cms\Models\ErrorCode;
use Maatwebsite\Excel\Concerns\FromCollection;

class ExportService implements FromCollection
{
    public function collection()
    {
        return ErrorCode::all();
    }
}
xugege
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

大佬 ,这个问题解决了吗?我在另外一个项目正常运行,新项目配置都没问题,但是就和你一样报这个错

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!