-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
BaseConfig should support array values with dot syntax #454
Comments
I ran into the same issue when created a basic mail library for my application, seems to be because loading using dot syntax isn't recursive and only looks a few levels deep? |
That's what I thought it was, but I just realized that it seems to work fine for database config options, which is very similar to the mail options I've been working on. So this will probably take a little more investigation. :) |
Hello, just a note on this same topic. I am using current latest code (#df60c1b2) and I cannot load database config from .env file. .env:
Database.php:
Migration tries to connect using mysql, it doesn't use the postgres credentials I specified in .env file. Also, even if i provide correct credentials in Database.php, migration still fails:
OS: macOS 10.12.4 And, yes, I have postgres, mysql php extensions installed. (My other PHP projects successfully connects to Postgres database) |
@DavisMiculis Where is your .env file? It sounds like it's not loading it. It should be under the root directory, not Additionally, it seems to be handling array values with dot syntax just fine, though I need to do some more tests to see why it wasn't working with my mail stuff. |
Ok, looks like my mail stuff wasn't working simply because it was deeper than the database config file is. So, the solution is either to simplify the mail config file or make BaseConfig recursive to deal with any depth - and that's probably the best solution. |
Didn't even notice it was moved. Ok, so I moved .env file to root directory. Now here's something interesting: But it still throws me errors:
|
PR 618 has unit tests for Config, including dot array syntax. |
@jim-parry IIRC, the issue is that it needs to handle it recursively. I believe it does it one or two levels deep only currently. The other option is that we ditch the automatic setting of values since it is fairly magic, and provide a custom env() function to read values from the three places dotenv sets them. I've been thinking about that lately, but not sure what everyone else thinks.... |
can you allow to put function in database.php to use like 'database' => env('database.default.username', 'testdb'), |
@ujjaldutta I use the env file for database config all of the time. Here's an example from my .env file:
And the db config is all default. However, there is an |
@jim-parry What are your thoughts on removing the magic in the BaseConfig file altogether and just using the |
Hi, |
@ujjaldutta Probably a typo.... and one that doesn't have anything to do with this issue. :) |
@jim-parry Since I haven't heard back an opinion just yet, I'm going to assume that means you're cool with scrapping the magical nature of BaseConfig. :) Seriously, though, I'm leaning very heavily toward doing that because it's a magic box that is hard to debug when it doesn't work quite right. using
If you don't have any issues, or if I don't hear from you in the next few days, I'll go ahead and remove that feature. |
@lonnieezell Sorry - I thought I had commented, but I agree - it isn't here :-/ |
No worries. The main problem I have isn't that it's magic, it's that it's unclear how it's happening, and a PITA to debug when you're trying to get the right config value in the .env file. Since you're good either way, I'll go ahead and simplify that aspect. Won't lose any power and is clearer to boot. |
Or maybe not. I remember why I did that now. You can't implement expressions as default values. This is the one time that using a class for a config value really gets in the way, as compared to a simple array. :( Guess it will stay. The alternative is ugly. |
@ujjaldutta For your previous comment: no, we cannot allow use of Instead, you can do it inside the constructor, though.
|
@lonnieezell Can we close this? anything else to fix or is this still a release blocker? |
I wouldn't say it's a release blocker, but is still a feature that would be nice to have, since dot array syntax works elsewhere. The main, thing, though, is that it should be updated to be recursive so it can handle more than 1 or 2 levels deep that it currently does. |
Fixed with #2082 |
Currently, I don't believe it loads those correctly. Check loading database group settings for a specific example.
The text was updated successfully, but these errors were encountered: