Laravel - 调用未定义的方法Illuminate \ Foundation \ Application :: share()

时间:2017-08-31 10:22:51

标签: php laravel

我正在从Laravel 5.3升级到Laravel 5.4。问题是,当我运行composer update时,当涉及php artisan optimize部分时,我收到错误:

[Symfony\Component\Debug\Exception\FatalErrorException]
  Call to undefined method Illuminate\Foundation\Application::share()

我在StackOverflow上阅读了几个问题,答案是用singleton替换这个share方法。但是我在哪里可以找到share()

修改

我的composer.json文件:

    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "sngrl/sphinxsearch": "dev-master",
        "laravelcollective/html": "5.4.*",
        "aws/aws-sdk-php-laravel": "~3.0",
        "league/flysystem-aws-s3-v3": "^1.0",
        "mcamara/laravel-localization": "1.2.*",
        "league/csv": "^8.2",
        "mikehaertl/phpwkhtmltopdf": "^2.2",
        "barryvdh/laravel-snappy": "^0.3.3",
        "wemersonjanuario/wkhtmltopdf-windows": "dev-master",
        "nesbot/carbon": "^1.22",
        "uxweb/sweet-alert": "^1.4",
        "laracasts/flash": "^2.0",
        "guzzlehttp/guzzle": "^6.2",
        "illuminate/support": "5.4.*",
        "laravel/scout": "^3.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

1 个答案:

答案 0 :(得分:1)

Project Share()方法文件是以下路径:

您的项目>>供应商>> laravel>>框架>> src>>发光>>容器>> Container.php

评论您的share()方法代码并将代码放在下面。

public function singleton($abstract, $concrete = null)
{
   $this->bind($abstract, $concrete, true);
}