Laravel Class env does not exist

17 Mar 2019 . Tips and Tricks . 1.2K views

Sometimes, there is an error in Laravel called Class env does not exist specially when you are trying to do PHP unit test on any specific class. In that case, although your test is right, however, it's always shows that Class env does not exist as a result the test is failed.

To solve this issue, I figure it out two possible ways.

Way 1:

If you are lucky enough, you may run the following commands to fix that issue-

php artisan clear
php artisan config:clear

However, in most of the cases, it might not be helpful. Specially in my case, it doesn't help. So that, I move to the next way out.

Way 2:

I realised that, it happened mostly for Laravel telescope package. I personally don't use that. So that, I just take off the package.

To remove that package, you need to remove the following items-

Go to composer.json Find this line "laravel/telescope" and remove the entire line.

Go to config/app.php file and remove the following line too-

App\Providers\TelescopeServiceProvider::class,

Once done, now you just run the following command in the terminal.

composer update
composer dumpautoload 
php artisan clear
php artisan config:clear

Hope it will help you. Thanks. :)