Laravel-Database
Laravel-Database copied to clipboard
Console commands not reading .env file
Today I tried to update one of my old PHP projects and wanted to have Laravel's Eloquent (and other gimmicks) without entire Laravel, so I used your project. But I hit an issue right away, when I configured it and tried to migrate the first migration.
The console commands were keep being rejected that it can't connect to the database set in .env file. After some debugging, I noticed that in https://github.com/Luracast/Laravel-Database/blob/master/bootstrap/autoload.php#L50 you're using createMutable, which does not make contents of .env available, but only as $_ENV variable.
Apparently, the Dotenv has been updated and they are now discouraging of usage getenv() directly and we should use $_ENV: https://github.com/vlucas/phpdotenv#putenv-and-getenv
After more digging around, I think that the change should be done here: https://github.com/Luracast/Laravel-Database/blob/master/bootstrap/helpers.php#L250 from $value = getenv($key) to $value = !empty($_ENV[$key]) ? $_ENV[$key] : $default.
My composer.json (partial):
"require": {
"php": "^7.4|^8",
"illuminate/cache": "^8",
"illuminate/database": "^8",
"illuminate/events": "^8",
"illuminate/filesystem": "^8",
"illuminate/pagination": "^8",
"league/flysystem": "^1.0",
"psy/psysh": "^0.10.4",
"symfony/process": "^5",
"vlucas/phpdotenv": "^5",
"ext-json": "*"
},
"require-dev": {
"doctrine/dbal": "~2.10",
"fakerphp/faker": "^1.19",
"illuminate/console": "^8",
"illuminate/view": "^8",
"laravel/helpers": "^1"
},
@DePalmo have you found a fix concerning this issue ?
I am trying to run migrations on a docker database, using pgsql or sqlite, i always get the same error : could not find driver (SQL: select * from information_schema.tables where table_schema = database and table_name = migrations and table_type = 'BASE TABLE')
Do you know if this could be related ?