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
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1

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

2年前 评论

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