Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sickaustrian's avatar

Undefined method Illuminate\Foundation\Application::share() when upgrading to Laravel 5.4

Hello, I just tried to upgrate Laravel 5.4 by updating my laravel/framework dependency to 5.4.* in my composer.json file. Once i run composer update I get the following error message:


> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize

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

Script php artisan optimize handling the post-update-cmd event returned with error code 1
vagrant@homestead:~/sites/Project$ 

Any ideas why? Thank you in advance!

0 likes
10 replies
sickaustrian's avatar

@usman Thank you for your quick reply. Where exactly do I have to update share to singleton then?

Bom_Basti's avatar

Could you show us your composer.json file?

1 like
sickaustrian's avatar

@R314x3 sure!

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "guzzlehttp/guzzle": "~6.0",
        "laravel/framework": "5.4.*",
        "spatie/laravel-fractal": "^3.2",
        "tymon/jwt-auth": "^0.5.9"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "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",
        "sort-packages": true
    }
}
sickaustrian's avatar

@ R3l4x3, I see thank you. I guess I wait until the issue is resolved on github then.

huynhbathanh's avatar

I faced the same issue today when try to upgrade to Laravel 5.4.

After see the error message, I check the storage/logs/{log-file-today}.log to know exactly what the package is incompatible with Laravel 5.4.

5 likes
RathaKann's avatar

I had the same problem.. How to solve it.

1 like
v4lerio's avatar

Check old packages/classes from config/app.php - I removed the ones not ready to support Laravel 5.4 to make it works again.

1 like
usamarauf93's avatar

public function register() { $this->app['datatables'] = $this->app->instance('foo', function ($app) { $request = $app->make('yajra\Datatables\Request'); return new Datatables($request); } ); }

2 likes

Please or to participate in this conversation.