How to change variables in the .env file dynamically in Laravel?

前端 未结 7 948
无人共我
无人共我 2020-11-28 08:16

I want to create a Laravel web app that allows an admin user to change some variables(such as database credentials) in the .env file using the web backend system. But how do

7条回答
  •  死守一世寂寞
    2020-11-28 09:03

    Another option is using config file instead changing content in .env file

    Put these all in any config files named like newfile.php inside config folder. If you actually dont' want to change .evn content. and treat these all as variable/array element.

     "",
        'PUSHER_APP_KEY' => "",
        'PUSHER_APP_SECRET' => "",
        'PUSHER_APP_CLUSTER' => "",
    ];
    

    And get/set in controller like below

    config(['newfile.PUSHER_APP_ID' => 'app_id_value']);//set
    
    config('newfile.PUSHER_APP_ID');//get
    

提交回复
热议问题