Laravel 5 environment config arrays?

后端 未结 2 1584
借酒劲吻你
借酒劲吻你 2021-01-04 07:05

In Laravel 4, you could set an environment based config folder structure:

/config/app.php
/config/dev/app.php
/config/staging/app.php
/config/testing/app.php         


        
2条回答
  •  春和景丽
    2021-01-04 07:44

    Generally for Phpdotenv

    Phpdotenv is about storing values in environment, not general purpose config library. Environment is UNIX concept and the values are always interpreted as character strings. Converting to different datatypes such as arrays or booleans even though convenient would be outside the scope of this class.

    Laravel config system

    Laravel's config system is already separated. phpdotenv does environment, laravel does config. Then once config is done, environment is ignored. The concern of parsing environment variables from strings into whatever is passed on to laravel (weather that be their env function, or exploding inside your config files).

    Good practice

    In other words, use Config::get() to get a specific conf file with your desired structure and you have what you need.

    You should never use env() in the code directly when it is outside of the config folder according to the Laravel guidelines. It's a good practice to use config(). In config files use env() to get the data from .env file.

提交回复
热议问题