如何解决在 Laravel 包开发中使用 Laravel Excel
我是第一次创建自己的 Laravel 包。我创建了一个新项目并在项目中需要 orchestra/testbench。一切正常,我可以在包内运行测试,但我无法在包内使用 Laravel Excel。
在 composer.json 中我添加了
"extra": {
"laravel": {
"providers": [
"Maatwebsite\\Excel\\ExcelServiceProvider"
],"aliases": {
"Excel": "Maatwebsite\\Excel\\Facades\\Excel",}
}
},"require-dev": {
"orchestra/testbench": "6.0","PHPunit/PHPunit": "^9.5","maatwebsite/excel": "^3.1"
}
并且还运行了 composer dump-autoload
,当我想在我的包中使用 Laravel Excel 时,我尝试了
use Maatwebsite\Excel\Facades\Excel;
class TaxCalculation {
public function incoMetax(): float
{
$table = Excel::import(new TaxImport(),'file.xls');
}
但是出错了
Illuminate\Contracts\Container\BindingResolutionException: Target class [excel] does not exist.
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Container\Container.PHP:832
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Container\Container.PHP:712
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Foundation\Application.PHP:796
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Container\Container.PHP:651
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Foundation\Application.PHP:781
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Container\Container.PHP:1354
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.PHP:198
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.PHP:166
D:\code\packages\thai_tax\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.PHP:255
D:\code\packages\thai_tax\src\Services\TaxCalculation.PHP:45
D:\code\packages\thai_tax\tests\Unit\CreateFacadeTest.PHP:26
Caused by
ReflectionException: Class excel does not exist
Excel 似乎无法加载。我还需要执行其他步骤才能使用它吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。