【问题标题】:How to add custom config file to app/config in Laravel 5?如何在 Laravel 5 中将自定义配置文件添加到 app/config?
【发布时间】:2016-12-04 14:08:54
【问题描述】:

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

【问题讨论】:

    标签: php laravel laravel-5 configuration


    【解决方案1】:

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

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

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

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

    config('constants.pagination.items_per_page');
    

    config('file_name.variable_name');
    

    【讨论】:

    • 我们需要在创建新的配置文件后运行php artisan config:cache,否则它不会加载。
    • 在开发时停止缓存你的配置,没有必要
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      相关资源
      最近更新 更多