0

I have updated application to Laravel latest version 5.8 and after update the getenv() function which returns env file variable value is returning false.

However when i used env() I am able to get the env variable value.

I have followed the official documentation and nothing is there which suggest to change from getenv() to env().

https://laravel.com/docs/5.8/configuration

Here suggesting to change to env from getenv()

PHP Dotenv

Please suggest if i need to change every reference of getenv to env or there is another way out.

miken32
  • 42,008
  • 16
  • 111
  • 154
Puneet Kushwah
  • 1,495
  • 2
  • 17
  • 35
  • 2
    "I have followed the official documentation and nothing is there which suggest to change from getenv() to env()." Because they've *always* told you to just use `env()`, I presume. You are probably going to have to replace your `getenv` calls. – ceejayoz Mar 18 '19 at 17:13
  • @ceejayoz: getenv() is php method which should work irrespective of framework (laravel here), there was a change which was reverted in 5.8.5 hence now it works fine. – svikramjeet Apr 15 '19 at 09:32
  • @svikramjeet Right, but if you're using Laravel, using `env()` gets you any *additional* functionality Laravel's implementation may add to the default (either now or in the future). As someone pointed out in the answers, the two even have different functionality currently; Laravel's has a second, useful parameter. – ceejayoz Apr 15 '19 at 13:06

3 Answers3

2

The correct way to do it is by changing from getenv to env. Also, getenv doesn't have a second parameter to set a default value.

0

There was specific version of laravel (5.8.4) where getenv was returning false, this has been updated in 5.8.5 or above.

Please check here

svikramjeet
  • 1,779
  • 13
  • 27
0

Try clearing your cache php artisan config:clear, php artisan cache:clear

Felix Coker
  • 51
  • 2
  • 2