No option to pass through existing env vars as well as auto-reload on env change #43489
Replies: 2 comments
-
After hours of debugging why serve via sail didn't respect the DB docker-compose.yml environment variables I set, I came across this. I fixed it by adding to my bootstrap/app.php: ServeCommand::$passthroughVariables[] = 'DB_HOST';
ServeCommand::$passthroughVariables[] = 'DB_PORT'; And added warning comments in both here and docker-compose.yml to keep the list in sync. Then I realized that it used loose comparison ServeCommand::$passthroughVariables[] = true; I don't really know the downside of this... The only thing I can think of is potential confusion on a developer's part if the change the |
Beta Was this translation helpful? Give feedback.
-
Sadly, this isn't true if you're using the serve command, so you need to allow the passthroughVariables as per above:
This allows DB_HOST, etc to be passed through from the environment to PHP and therefore Laravel. Perhaps the docs should be updated to reflect this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
framework/src/Illuminate/Foundation/Console/ServeCommand.php
Lines 135 to 139 in e7ac9b1
I'm running Laravel sail in a devcontainer. I'd like to be able to pass through most environment variables to multiple containers so that I can set up MySQL with certain credentials, and use the same env vars in Laravel to connect to the database, for instance. However, I found that serving Laravel through
php artisan serve
will block most environment variables from the "outside" environment. This means I'd have to duplicate all my variables to the .env file for my Laravel app, or use "--no-reload", in which case the filter is ignored. Wouldn't it be possible to have both?Beta Was this translation helpful? Give feedback.
All reactions