简体   繁体   English

如何在 Laravel 5 中向 app/config 添加自定义配置文件?

[英]How to add custom config file to app/config in Laravel 5?

I want to add custom_config.php to app/config directory of my Laravel 5 project, but can't find any article explaining this process.我想将custom_config.php添加到我的 Laravel 5 项目的app/config目录中,但找不到任何解释此过程的文章。 How is this done?这是怎么做的?

You can easily add a new file to the config folder.您可以轻松地将新文件添加到 config 文件夹。 This file should return configuration values.此文件应返回配置值。 Check other config files for reference.检查其他配置文件以供参考。 Say constants.php is like soconstants.php就是这样

<?php

return array(
    'pagination' => array(
           'items_per_page' => 10
    ),
);

You can now access this config file from anywhere by either using the Config Facade or the config() global function like so您现在可以使用Config Facade 或config()全局函数从任何地方访问此配置文件,如下所示

Config::get('constants.pagination.items_per_page');

or

config('constants.pagination.items_per_page');

ie

config('file_name.variable_name');

我不知道一个人可能需要创建多少次配置文件,但是这里有一个 Artisan 命令: https : //gist.github.com/jotaelesalinas/eafd831048ca5fb5fba970afd1921f70

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM