kaylakaze
4604
30
General

.env Not Reading Variables Sometimes

Posted 3 years ago by kaylakaze

I've set up a custom variable in my .env file, DISPLAY_TZ, to designate the timezone that the app should display times in. I have the User $tz variable being set to this using getenv('DISPLAY_TZ')?:date_default_timezone_get() and then used by calling setTimezone(Auth::user()->tz) on my Carbon object in the view. Seemingly at random, the times displayed will be in UTC (the date_default value) and not America/New_York (the .env value). I don't think this is a Carbon issue, because when I change it to getenv('DISPLAY_TZ')?:'America/New_York' it's always correct. My app loads many pieces of the page via AJAX, if that could be the issue? Also, seemingly at random, some of my AJAX calls will return my access denied page (I'm using Laraguard) even when I have access to the page and a refresh fixes it. I'm wondering if it's related. I'm using SQLite for my database so I'm not using any database variables from the .env so I wouldn't know if those are also not loading.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.