Laravel 5 - 配置子文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29226956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:12:07  来源:igfitidea点击:

Laravel 5 - Config sub-folder

phplaravelconfiglaravel-5

提问by user1995781

In Laravel 5, we can read a config value via this:

在 Laravel 5 中,我们可以通过以下方式读取配置值:

config('app.url')

But, how can we read config file value in the sub-folder? I have tried with config('subfolder/app.url')but it didn't work.

但是,我们如何读取子文件夹中的配置文件值?我试过,config('subfolder/app.url')但没有用。

回答by Kamran

You can do like this in laravel 5 config('subfolder.myfile.var'); subfolderis folder name , myfileis your file name and varis your variable.

你可以在 laravel 5 中这样做 config('subfolder.myfile.var')subfolder是文件夹名称,myfile是您的文件名,var是您的变量。

回答by jartaud

I've created: config/local/app.php containing:

我已经创建: config/local/app.php 包含:

<?php return [ "key" => "value" ];

<?php return [ "key" => "value" ];

and using artisan, here's what i got:

并使用工匠,这就是我得到的:

enter image description here

enter image description here

回答by kamlesh.bar

Create Folder with name subfolderinside configdirectory create file app.php

配置目录中创建名为子文件夹的文件夹创建文件app.php

Inside app.php put all your constants

里面 app.php 把你所有的常数

return array(
        'APP_URL'  => 'http://www.test.com/xyz',
        'APP_MAX_FOLDER_SIZE' => 1000000000,
);

and access like

和访问像

config('subfolder.app.APP_URL');

it is advisable to create constants in Upper caseletter and create file name that makes sense like constans.phpor appconstants.phpetc

最好是建立在常量大写字母和创建文件名是有道理像constans.phpappconstants.php