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


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

我想将custom_config.php添加到我的Laravel 5项目的app/config目录中,但找不到任何解释此过程的文章。这是怎么做到的?

您可以轻松地将新文件添加到config文件夹中。此文件应返回配置值。请检查其他配置文件以供参考。假设constants.php是这样

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

现在,您可以使用configFacade或config()全局函数(如)从任何地方访问此配置文件

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

config('constants.pagination.items_per_page');

config('file_name.variable_name');

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