【发布时间】:2016-12-04 14:08:54
【问题描述】:
我想将custom_config.php 添加到我的 Laravel 5 项目的 app/config 目录中,但找不到任何解释此过程的文章。这是怎么做到的?
【问题讨论】:
标签: php laravel laravel-5 configuration
我想将custom_config.php 添加到我的 Laravel 5 项目的 app/config 目录中,但找不到任何解释此过程的文章。这是怎么做到的?
【问题讨论】:
标签: php laravel laravel-5 configuration
您可以轻松地将新文件添加到配置文件夹。此文件应返回配置值。检查其他配置文件以供参考。说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,否则它不会加载。
我不知道创建配置文件可能需要多少次,但这里有一个 Artisan 命令:https://gist.github.com/jotaelesalinas/eafd831048ca5fb5fba970afd1921f70
【讨论】: