I am reading some configurables from my .env file. These configurables are used in various places within the project. A few times i've received an exception that one of the env variables does not exist. eg.
ini_set(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function.
In my .env I have this:
TIMEZONE=Africa/Johannesburg
In the boot function of my AppServiceProvider I have:
ini_set('date.timezone', getenv('TIMEZONE'));
It's as if the .env hasn't loaded at the time im trying to use one of its variables? Ive seen this happen for a few different .env variables at various stages during the application running.
in your config/app.php file there is this line:
'timezone' => env('TIMEZONE', 'UTC'),
to fetch the env value use: config('app.timezone')
also see this: https://laravel.com/docs/5.2/configuration#accessing-configuration-values
ITCan said:
in your config/app.php file there is this line:
'timezone' => env('TIMEZONE', 'UTC'),
to fetch the env value use: config('app.timezone')
also see this: https://laravel.com/docs/5.2/configuration#accessing-configuration-values
We can't use config for our environments. I have to use .env
This example is just 1 scenario where we are using .env for configurables and now and then any of them act-up.
lagbox said:
You dont use env outside of config files.
Well if .env uses DB connection info then I don't see the problem with using it for additional configurables? I have to use .env because we have dev-ops that deploy our code + I don't have access to the servers. The application is deployed to multiple servers which can point to other servers for connections and the dev-ops decide on which servers each version of the application connects to. From a security POV I don't know the server IP addresses and i'm not allowed to hard-code them in with switches in config. A load balancer handles connections. This is for a banking environment.
I simply don't understand why .env is not loading 100% of the time.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community