Solve: Laravel env() Variable Always Returns Null Value
The problem mainly occurs at the time of moving our project one server to another server. I’m writing about some possible solutions.
Make sure you have
.env file at the root directory of your Laravel project. If there is no .env file, the rename
Sometimes it occurs for cache. You can clear configuration cache using following commands:
php artisan config:clear php artisan optimize php artisan config:cache
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:
That’s it. Thank you. ?
php artisan clear-compiled composer dump-autoload php artisan optimize
Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.