why some variable are not .enviable by default?

Published 2 months ago by boynet

for example in config/app.php the time zone used like 'timezone' => 'UTC'

so If I want to change this value inside .env I need to edit the config files directly, why not all options are there by default? it make me think that maybe I should not change those?

Best Answer (As Selected By boynet)
ctroms

I don't see any reason why you couldn't add the timezone to your .env if you wanted to. Just make sure you update your config/app.php

'timezone' => env('ENV_TIMEZONE', 'UTC'),

If I had to guess as to why it might not be there by default; .env files are not committed to your repo.

If the timezone is set on your local machine in .env and left as a default in your config/app.php, you might be developing with your app configured for one timezone and the production code configured for another.

This can negatively effect your application including logging and reporting especially if your logs are pulled to a central location.

For non secret things that you want to stay consistent across all developers machines you might just consider leaving them hard coded in config/app.php

ctroms

I don't see any reason why you couldn't add the timezone to your .env if you wanted to. Just make sure you update your config/app.php

'timezone' => env('ENV_TIMEZONE', 'UTC'),

If I had to guess as to why it might not be there by default; .env files are not committed to your repo.

If the timezone is set on your local machine in .env and left as a default in your config/app.php, you might be developing with your app configured for one timezone and the production code configured for another.

This can negatively effect your application including logging and reporting especially if your logs are pulled to a central location.

For non secret things that you want to stay consistent across all developers machines you might just consider leaving them hard coded in config/app.php

goatshark

@boynet Are you asking why all config options are not .env variables? I suppose you can make whatever you want an environment variable.

'timezone' => env('MYTIMEZONE', 'UTC')

...and then add to .env file:

MYTIMEZONE=UTC (or whatever you want it to be)

If this does what you want, make sure to place any environment variables you create into .env.example so you're tracking them.

boynet

@ctroms thanks I guess that it make some sense

I was looking for a way to never touch the laravel files for easier framework upgrade so now when a new version come out I will need to recheck for changes the all configs files

ctroms

@boynet No problem!

You can also checkout tools like (Laravel Shift)[https://laravelshift.com/] to save time during upgrades.

Sign In or create a forum account to participate in this discussion.