laravellaravel-8laravel-cache

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


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?


Solution

  • 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.