调用未定义的方法App \ Console \ Kernel :: load()-Laravel 5.4

时间:2018-11-14 05:41:13

标签: php laravel

我将应用程序从5.5 to 5.4降级,运行php artisan serve时出现此错误

  
    

调用未定义的方法App \ Console \ Kernel :: load()-Laravel 5.4

  

考虑其他解决方案,我运行composer dump-autoload来解决此问题,但该问题仍然存在。同样的错误。我真的不知道这是否是由我下面下面的composer.json文件中的包引起的

我现在该怎么解决?

预先感谢

Composer.Json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "barryvdh/laravel-dompdf": "0.8.*",
        "fideloper/proxy": "~4.0",
        "guzzle/guzzle": "~3.0",
        "laravel/framework": "5.4.*",
        "laravel/passport": "^3.0",
        "laravel/tinker": "~1.0",
        "laravelcollective/html": "~5.0",
        "maatwebsite/excel": " ~2.1.0",
        "pda/pheanstalk": "~2.0",
        "picqer/php-barcode-generator": "^0.2.0",
        "spatie/laravel-permission": "^2.12",
        "yajra/laravel-datatables-oracle": "~8.0"
    },
    "require-dev": {
        "filp/whoops": "~2.0",
        "nunomaduro/collision": "~1.1",
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "~1.0",
        "phpunit/phpunit": "~7.0",
        "symfony/thanks": "^1.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories",
            "app/commands",
            "app/models",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ],
        "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
}

3 个答案:

答案 0 :(得分:1)

问题是您不能确保将代码更新为与Laravel 5.4兼容。

在Laravel 5.5+随附的Kernel.php样板中,有一行

$this->load(__DIR__.'/Commands');

5.5中添加了此命令,以自动检测app / Console / Commands目录中的任何命令。

为了使此代码在5.4中工作,您需要删除该行并在protected $commands = [ ]数组下的同一文件中手动注册所有命令。

load的源代码位于https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Console/Kernel.php#L196中,如果您想尝试对其进行修改并将其放在自己的Kernel.php

答案 1 :(得分:0)

运行composer install命令后删除供应商文件夹和composer.lock文件

答案 2 :(得分:0)

转到your_project / app / Console / Kernel.php并删除行

  

$ this-> load( DIR 。'/ Commands');

在commands()函数中