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();
}
}
大佬 ,这个问题解决了吗?我在另外一个项目正常运行,新项目配置都没问题,但是就和你一样报这个错