在Laravel 5.7上找不到类'Laravel \ Passport \ Passport'

时间:2019-03-18 16:20:17

标签: laravel laravel-5 composer-php laravel-passport

我只是将clonedrepoLaravel 5.7 project一起使用,在我的计算机上运行它遇到了一些麻烦。

当我制作一个composer install时,我得到了这个error

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover

In AuthServiceProvider.php line 35:

  Class 'Laravel\Passport\Passport' not found


Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1

我该怎么做才能解决此错误?我不知道从哪里开始。

这是项目的composer.json file

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "designmynight/laravel-mongodb-passport": "^1.1",
        "fideloper/proxy": "^4.0",
        "guzzlehttp/guzzle": "^6.3",
        "jenssegers/mongodb": "^3.4",
        "laravel/framework": "5.7.*",
        "laravel/passport": "^7.0",
        "laravel/tinker": "^1.0"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

2 个答案:

答案 0 :(得分:3)

尽管composer update会根据情况进行欺骗,但这可能不是最佳解决方案。

首先-运行composer install时,将基于composer.lock中的版本(如果应该包含)安装软件包。

在您的情况下,当您仔细查看控制台输出时,您会得到:

  

警告:锁文件不是最新的composer.json更改。您可能会过时的依赖关系。运行更新以更新它们。

因此,很可能有人将Laravel Passport软件包添加到了composer.json,但没有运行composer install或忘记了提交更新的composer.lock文件。

现在请记住,在运行composer update时,您将更新所有软件包。有时很好(仅在localhost上),但有时又不可行,因为并非总是要更新所有软件包。因此,当您需要更新单个软件包时,也可以在这种情况下尝试composer update laravel/passport来仅强制更新/安装Laravel Passport而无需接触其他软件包。

答案 1 :(得分:2)

您似乎需要做

composer update 

代替安装?