3

Not sure why I am getting this message:

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Dotenv\Dotenv' not found in /home/vagrant/devbox/devbox.local/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php on line 24

Below is the DetectEnvironment.php code:

<?php

namespace Illuminate\Foundation\Bootstrap;

use Dotenv\Dotenv;
use Dotenv\Exception\InvalidPathException;
use Symfony\Component\Console\Input\ArgvInput;
use Illuminate\Contracts\Foundation\Application;

class DetectEnvironment
{
    /**
     * Bootstrap the given application.
     *
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return void
     */
    public function bootstrap(Application $app)
    {
        if (! $app->configurationIsCached()) {
            $this->checkForSpecificEnvironmentFile($app);

            try {
                (new Dotenv($app->environmentPath(), $app->environmentFile()))->load();
            } catch (InvalidPathException $e) {
                //
            }
        }
    }

My project had been working correctly until I restarted the computer and server. Whenever I go to the site or run a composer or artisan command I get the error above.

I have tried various solutions that I have found but none have worked. This includes:

  • specifically adding vlucas/phpdotenv to the composer file (it already existed in the vendor file structure, but added it to make sure)
  • running composer update and composer dumpautoload
  • creating a new .env file

Creating a new laravel project works, but I really don't want to have to do that (there must be an easy explanation/fix for this).

Similar issues as listed in, but neither have answers that work for me:

I am using the latest Laravel version and running it on Homestead.

Any guidance is greatly appreciated!

2 Answers 2

1

Try deleting the contents (not the directories themselves) in /bootstrap/cache/, and delete your /vendor/compiled.php, then run composer install again.

1

You should require Dotenv. Use this composer command:

require vlucas/phpdotenv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.