'Fatal error: Uncaught ReflectionException: Class "env" does not exist

After lunching the command php artisan optimize , i got

fatal error: Uncaught ReflectionException: Class "env" does not exist

I have tried deleting the bootstrap/cache/ and runing composer update but nothing works, everytime i tried to run a php artisan command/composer command i got the same problem. am really stuck. any help.



Solution 1:[1]

You can clear cache using:

php artisan optimize:clear

Or only clear config cache using:

php artisan config:clear

https://dev.to/kenfai/laravel-artisan-cache-commands-explained-41e1

Solution 2:[2]

Maybe you have something wrong in your config/database.php file. If it is the case when you run composer update the console will show some error at the end of execution due the config/database.php file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Lester Potestad Berovides