Hello guys I am so confused I dont know what I am doing wrong this told me Fatal error: Class 'Dotenv\Dotenv' not found in
But I dont understand why..
$dotenv = new \Dotenv\Dotenv(dirname(dirname(dirname(dirname(__DIR__)))));
$dotenv->load();
My structure is the next and in the file index.php is where I am calling Dotenv also I used use Dotenv\Dotenv; but it doesnt work too.
Be sure that you are using Dotenv after loading from vendor/autoload.php
.
For example, I was using OpenCart, in which contained a file startup.php
with:
// Autoloader
if (file_exists(DIR_VENDOR . 'autoload.php')) {
require_once(DIR_VENDOR . 'autoload.php');
}
And I had defined DIR_VENDOR
in config.php
as:
define('DIR_VENDOR', __DIR__.'/vendor/');
So finally, in index.php
, I would have:
// Startup
require_once(DIR_SYSTEM . 'startup.php');
// dotenv
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
So startup.php
loads vendor/autoload.php
, which loads vlucas/phpdotenv
, after which we can then find Dotenv\Dotenv
.
just remove/delete the vendor
folder and reinstall with the -> composer install
.
check if you have "vlucas/phpdotenv" : "~2.2" in "require" tag in composer file. if you don't then add that plugin and open your terminal and run "composer dump-autoload" then run "composer update". and just to be safe run "composer dump-autoload" once again to refresh all the file paths.
and, if you do have phpdotenv plugin then add that plugin in "require" then just run the dump-autoload command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With