在 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 (将#修改为@)