How to set .env values in laravel programmatically on the fly

前端 未结 14 991
忘掉有多难
忘掉有多难 2020-12-01 09:05

I have a custom CMS that I am writing from scratch in Laravel and want to set env values i.e. database details, mailer details, general configuration, etc from

14条回答
  •  再見小時候
    2020-12-01 09:45

    Since Laravel uses config files to access and store .env data, you can set this data on the fly with config() method:

    config(['database.connections.mysql.host' => '127.0.0.1']);
    

    To get this data use config():

    config('database.connections.mysql.host')
    

    To set configuration values at runtime, pass an array to the config helper

    https://laravel.com/docs/5.3/configuration#accessing-configuration-values

提交回复
热议问题