如何解决LaravelExcel:找不到界面“App\Exports\FormView”
我正在使用 Laravel 5.8 和 PHP 7.4 来开发我的项目,在这个项目中,我想从 View 中名为 students
的表中创建一个 Excel 文件。
这就是我所做的:
我在终端输入 composer require maatwebsite/excel
并下载了软件包。
我在 \Maatwebsite\Excel\ExcelServiceProvider::class,
的 providers
中添加了 config/app.php
,并将 'Excel' => \Maatwebsite\Excel\Facades\Excel::class,
添加为 aliases
。
然后制作了这个新的导出文件:
php artisan make:export StudentExportView --model=App\Member\Student
这个文件保存了这个:
namespace App\Exports;
use App\Member\Student;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FormView;
use Maatwebsite\Excel\Facades\Excel;
class StudentExportView implements FormView
{
/**
* @return \Illuminate\Support\Collection
*/
public function view(): View
{
return view('admin.students.custom',[
'customs' => Student::all()
]);
}
}
在控制器中,我添加了这个方法:
public function export_view()
{
return Excel::download(new StudentExportView,'students.xlsx');
}
还有这些到web.php
的路线:
Route::get('export_view','StudentAdminController@export_view')->name('students.export_view');
但是当我出去的时候,我得到这个错误:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
找不到接口“App\Exports\FormView”
所以这里出了什么问题?
注意
如果我从导出类中删除 use Maatwebsite\Excel\Concerns\FormView;
,一个 空 excel 文件下载
包裹是"maatwebsite/excel": "^3.1"
解决方法
它的 FromView
不是 FormView
。
use Maatwebsite\Excel\Concerns\FromView;
class StudentExportView implements FromView
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。