can not get env file attribute after using php artisan optimize in laravel

686 Views Asked by At

I am getting attribute value from env file like this

{{env('PUSHER_APP_KEY')}}

It stops working when i use php artisan optimize command

Then Again I have to use php artisan config:clear

What could be the solution of it?

1

There are 1 best solutions below

3
John Lobo On BEST ANSWER

Better create a config file in config folder

For example name config file as constant.php

<?php

return [
'pusher_app_key'=>env('PUSHER_APP_KEY')
];

then you can access like this

{{config('constant.pusher_app_key')}}

once you have created config:cache then it wont read from env file.