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

ElMorin's avatar

How to fix artisan? php artisan optimize throws a [ReflectionException]

First of all, this is the actual error in git bash :

php artisan optimize

[ReflectionException]
Class hash does not exist

None of my artisan command are actually working. Earlier today, it was. Since i'm using git, I tried to find in the code I change what could be the error. No success.

I'm using Laravel 5.4.36

php -v : PHP 7.1.9-1+ubuntu16.04.1+deb.sury.org+1

vagrant -v : Vagrant 2.0.0

Homestead version is 6.2.2

Homestead is installed on windows 10.

There is the list of step I tried to solve the problem.

-1.composer dump-autoload -> FAILED at php artisan optimize

-2.composer update -> FAILED at php artisan optimize

-3. Check if Hash is present in config\app.php

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    ....
    Illuminate\Hashing\HashServiceProvider::class,
    ....

    'aliases' => [
    ....
    'Hash' => Illuminate\Support\Facades\Hash::class,
    ....

-3.1 I look if this file exist : Illuminate\Support\Facades\Hash It exist.

-3.2 I look if this file exist : Illuminate\Hashing\BcryptHasher It exist.

-4. I runned sudo chgrp -R www-data storage bootstrap/cache and sudo chmod -R ug+rwx storage bootstrap/cache.

I don't think that step (4) really did something that could help to solve this problem...

-5. Tried composer dump-autoload again... Still FAILED at php artisan optimize

-6. I deleted the vendor document then run composer install FAILED at php artisan optimize

-7. I tried to run php artisan optimize in the file located localy on my windows and also into the file into the virtual machine. I know that both file are linked, but I wanted to see if there was a problem with one of the machine.

So, now I can't use php artisan <command> and I don't know what to do/try. Can you please help me fixing this! It will be appreciate!

0 likes
4 replies
thinkweis's avatar

Pretty much any time you get an exception you can't identify, go to your laravel.log in the storage folder and look at the last entry. You should be able to trace it back to where the error is being generated or even better, what file is calling that class so you can import that class.

ElMorin's avatar

I agree with you, pretty much any time. But not this time. The error happen somewhere in the beginning of the boot, so Log is not accessible at this time. I can't get the error in laravel.log file.

Please or to participate in this conversation.