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

夙愿已清 提交于 2020-11-30 04:34:31

问题


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. How is this done?


回答1:


You can easily add a new file to the config folder. This file should return configuration values. Check other config files for reference. Say constants.php is like so

<?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::get('constants.pagination.items_per_page');

or

config('constants.pagination.items_per_page');

i.e.

config('file_name.variable_name');



回答2:


I don't know how many times one might need to create a config file, but here you have an Artisan command for it: https://gist.github.com/jotaelesalinas/eafd831048ca5fb5fba970afd1921f70



来源:https://stackoverflow.com/questions/38665907/how-to-add-custom-config-file-to-app-config-in-laravel-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!