Skip to content

Console commands not reading .env file #16

@DePalmo

Description

@DePalmo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions