Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 7 - Class hash does not exist

I have a newly created Laravel application with Backpack installed in it. I am struggling to deploy it to Google Cloud for the past few days.

I'm using Laravel 7, I'm trying to deploy to Google cloud App Engine and getting Class hash does not exist error. Few times I've also gotten Class view does not exist.

I'm pretty sure that this is something to do with deployment environment rather than my changes. The reason for me to say this is, this morning I updated backpack/crud version and the application ran successfully after deployment.

So just to test, I deployed again without making any changes, zero files were uploaded and I ran into the same problem!

It would be great if someone can give me pointers to what I can try.

2020/07/09 23:42:46 [error] 20#20: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught ReflectionException: Class hash does not exist in /srv/vendor/laravel/framework/src/Illuminate/Container/Container.php:805
Stack trace:
#0 /srv/vendor/laravel/framework/src/Illuminate/Container/Container.php(805): ReflectionClass->__construct('hash')
#1 /srv/vendor/laravel/framework/src/Illuminate/Container/Container.php(687): Illuminate\Container\Container->build('hash')
#2 /srv/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(796): Illuminate\Container\Container->resolve('hash', Array, true)
#3 /srv/vendor/laravel/framework/src/Illuminate/Container/Container.php(633): Illuminate\Foundation\Application->resolve('hash', Array)
#4 /srv/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(781): Illuminate\Container\Container->make('hash', Array)
#5 /srv/vendor/laravel/framework/src/Illuminate/Container/Container.php(1280): Illuminate\Foundation\Application->make('hash')
#6 /srv/vendor/laravel/framework/src/Illuminate/Auth/CreatesUserPro...PHP message: PHP Fatal error:  Uncaught ReflectionException: Class hash does not exist in /srv/vendor/laravel/framework/src/Illuminate/Container/Container.php:805

My composer.json -

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2.5",
        "backpack/crud": "4.1.*",
        "backpack/permissionmanager": "^6.0",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^1.0",
        "guzzlehttp/guzzle": "^6.3",
        "intervention/image": "^2.5",
        "laravel/framework": "^7.0",
        "laravel/tinker": "^2.0",
        "superbalist/laravel-google-cloud-storage": "^2.2"
    },
    "require-dev": {
        "backpack/generators": "^3.1",
        "facade/ignition": "^2.0",
        "fzaninotto/faker": "^1.9.1",
        "laracasts/generators": "^1.1",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ],
        "post-install-cmd": [
            "composer clearcache",
            "chmod -R 755 bootstrap\/cache",
            "php artisan cache:clear",
            "php artisan config:clear"
        ]
    }
}

like image 842
Asif Avatar asked Oct 22 '25 03:10

Asif


1 Answers

I run into a similar problem quite often. Though not exactly the same, it may be similar enough that this will solve it for you. For me it is usually a cache issue with the build.

If this happens after a composer update, and you forget to do --no-dev and then remove stuff on the next update, this error may occur.

To Fix:

Either the no-dev issue, or perhaps a general cache issue with the build, manually go into the bootstrap/cache folder & remove the files, especially the packages file. Or, if you've set the environment as DEV, and you actually didn't pull in the dev packages, go back and composer update (without no-dev)

Alternatively, if you're still stuck, you can try to update composer with no scripts and then install. In my case, once it was still trying to load debugbar.

like image 99
Watercayman Avatar answered Oct 24 '25 02:10

Watercayman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!