Laravel .env variable always returns null

As per the Laravel document

“Once the configuration has been cached, the .env file will not be loaded and all calls to the env function will return null.”

You can find it here
https://laravel.com/docs/5.5/configuration#configuration-caching

The Best process is
1. Define the variables in .env file

APP_URL=http://swastikorganization.com/public

2. Use this variable in your config file.
=> constant.php file
‘APP_URL’=>env(‘APP_URL’, ‘Not Found’),

3. Call/ access it in your controllers

echo config(‘constant.APP_URL’);
dd(config(‘constant.APP_URL’));

Please follow and like us:
0

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.