Did anyone has issues with env
variables? For some reason, helper env('VARIABLE')
returns null
every time I use it. It happened very unexpectedly and I dont really know the reason. Restarting the apache/IDE/computer does not work.
In a fresh Laravel installation, the root directory of your application will contain a . env.
Go to your main project folder from your CPanel File Manager and look for . env file.
A simple way to update the . env key value in laravel is to add the below code in the controller function where you want to change . env values. $key = 'VARIABLE_NAME'; $value = 'NEW VALUE'; file_put_contents(app()->environmentFilePath(), str_replace($key .
Run those of command
composer dump-autoload php artisan cache:clear php artisan config:clear php artisan view:clear
Now try to read
$value = env('VARIABLE_NAME');
if not working till now then,
Try another syntax to read env variable.
$value=getenv('VARIABLE_NAME');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With