简体   繁体   English

Laravel 5:如何将自定义配置文件的目录从app / config更改为app / source?

[英]Laravel 5: How do I change the directory of my custom config file from app/config to app/source?

I have a repository in folder app/source and a second project share the app/source with my current project. 我在文件夹app / source中有一个存储库,第二个项目与当前项目共享了app / source。 I need to move my app/config/config.php into app/source so my second project has the same data. 我需要将我的app / config / config.php移到app / source中,以便我的第二个项目具有相同的数据。 How do I configure laravel to search for my custom config in app/source/config.php instead of app/config/config.php? 如何配置laravel在app / source / config.php中而不是app / config / config.php中搜索我的自定义配置?
I've tried to update my ConfiserviceProvider class to this: 我试图将我的ConfiserviceProvider类更新为:

class ConfigServiceProvider extends ServiceProvider
{
/**
 * Bootstrap the application services.
 *
 * @return void
 */
public function boot()
{
    //
}

/**
 * Register the application services.
 *
 * @return void
 */
public function register()
{
    config([
        'app/source/config.php',
    ]);
}
}

but this isn't working. 但这不起作用。
How do I fix this? 我该如何解决?

To include custom config file: 要包括自定义配置文件:

app('config')->set('custom', require app_path('source/config.php'));

For example if config.php file contains: 例如,如果config.php文件包含:

<?php

return [

    'foo' => 'bar'

];

Access it like that: 像这样访问它:

config('config.foo'); // return 'bar'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Laravel 5 中向 app/config 添加自定义配置文件? - How to add custom config file to app/config in Laravel 5? 我该如何选择在Laravel应用中存储其插件的自定义配置值? - How do I give an option to store custom config values for their plugins in my Laravel app? 如何在自定义Laravel 5.3配置文件中调用模型? - How do I call a model in a custom Laravel 5.3 config file? Laravel-如何从配置文件中获取命名路由? - Laravel - How do I get a named route from a config file? 在设置网站/应用程序时,我在什么目录中放置了我的mysql config.php文件? - In what directory do i put my mysql config.php files when setting up a website/app? Laravel 5.7在Controller中更改自定义配置文件? - Laravel 5.7 change custom config file in Controller? 如何使包配置将其不存在的键合并到 Laravel 7.x 中的应用程序配置文件中? - How can I make the package config merge it's non-existing keys into the app config file in laravel 7.x? 使用Laravel中的配置应用程序文件进行单元测试 - Unit testing with the config app file in Laravel 在App \\ Libraries Laravel中使用配置文件 - Use config file in App\Libraries Laravel 我们如何从数据库或laravel 5 config文件夹中app.php的其他文件中访问数据 - how do we access data from database or other files in app.php of the config folder in laravel 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM