Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console commands not reading .env file #16

Open
DePalmo opened this issue Dec 28, 2022 · 1 comment
Open

Console commands not reading .env file #16

DePalmo opened this issue Dec 28, 2022 · 1 comment

Comments

@DePalmo
Copy link

DePalmo commented Dec 28, 2022

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"
  },

@VincentLechasseur
Copy link

VincentLechasseur commented Jun 5, 2023

@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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants