Laravel 服务提供商 class 在分叉供应商中找不到

Laravel service provider class not found in forked vender

我正在开发一个在 Laravel 中运行良好的 repo。当我分叉回购协议时,我现在得到这个错误:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'DevIT\Hasoffers\Laravel\Providers\HasoffersServiceProvider' not found

我尝试在 app.php 中注释掉 provider 行,然后 运行 这些,然后取消注释该行,但这些都没有帮助:

composer dump-autoload
php artisan clear-compiled
php artisan optimize

这是 composer.json 中的配置:

"require": {
    "devit/hasoffers-php-client": "dev-master",
    "devit/hasoffers-laravel-client": "dev-master"
},
"repositories": [
    {
        "type": "package",
        "package": {
            "name": "devit/hasoffers-php-client",
            "version": "dev-master",
            "source": {
                "url": "https://github.com/ecomevo/hasoffers-php.git",
                "type": "git",
                "reference": "master"
            }
        }
    },
    {
        "type": "package",
        "package": {
            "name": "devit/hasoffers-laravel-client",
            "version": "dev-master",
            "source": {
                "url": "https://github.com/ecomevo/hasoffers-laravel.git",
                "type": "git",
                "reference": "master"
            }
        }
    }
],

如果我导航到供应商目录,该包就在那里,作曲家声称它是在最新更新期间引入的。

我哪里错了?

你的 composer 文件正在使用 package repositories,它不会读取被拉入的包的 composer.json 文件。因为 PSR-4 自动加载是在那些 composer.json 文件中定义的,它没有被设置,并且你的 class 没有被找到。

您可以将自动加载功能添加到您的包定义中,但最好的办法是使用 vcs repository type,这样它们的 composer.json 文件就会得到尊重。

您的作曲家文件应该类似于:

"require": {
    "devit/hasoffers-php-client": "dev-master",
    "devit/hasoffers-laravel-client": "dev-master"
},
"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/ecomevo/hasoffers-php"
    },
    {
        "type": "vcs",
        "url": "https://github.com/ecomevo/hasoffers-laravel"
    }
],

由于您已经使用之前的方法提取了这些包,您可能需要在执行作曲家更新之前清除作曲家缓存:

composer clearcache
composer update devit/hasoffers-php-client
composer update devit/hasoffers-laravel-client