'.env can't get read from inside a job

I have a Laravel project (v8.12) running on PHP 7.4.3 in a dedicated AWS instance with Ubuntu 20.04. When I try to read an environment variable from inside a job, the value is always null, but it works elsewhere. I tried to switch from supervisord to sync driver, still couldn't reach it.



Solution 1:[1]

Your problem could be from cache . you can below commands for remove cache .

php artisan cache:clear

php artisan config:clear 

php artisan view:clear 

Solution 2:[2]

Run below commands

 composer dump-autoload

 php artisan clear-compiled
 php artisan optimize

 php artisan route:clear
 php artisan view:clear

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

For Example

In your env file

 SITE_NAME="My website"

Get your env variable like

 $data = env('SITE_NAME');   
 echo $data;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Reza ghz
Solution 2 VIKAS KATARIYA