Solve: Laravel env() Variable Always Returns Null Value

Published on June 12, 2020 31 sec read

HIRE US 🖐
We're available to do freelance project. Take a look at our services!

The problem mainly occurs at the time of moving our project one server to another server. I’m writing about some possible solutions.

Solution 1

Make sure you have .env file at the root directory of your Laravel project. If there is no .env file, the rename .env.example to .env.

Solution 2

Sometimes it occurs for cache. You can clear configuration cache using following commands:

php artisan config:clear 
php artisan optimize
php artisan config:cache

Solution 3

If the above 2 solutions didn’t work, you run these additional commands.

These commands will clear cache, compiled views and routes cache:

php artisan cache:clear
php artisan view:clear
php artisan route:clear

These will clear the current compiled files, update the classes it needs and then write them back out so you don’t have to do it again:

php artisan clear-compiled 
composer dump-autoload
php artisan optimize
That’s it. Thank you. 🙂

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.
Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

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