laravel 5.1访问包配置值

时间:2015-06-18 08:14:22

标签: php laravel

我正在laravel 5.1上开始一个包。到目前为止使用laravel 4.2

我已经能够使用以下方法在我的包的服务提供者的boot方法中发布包配置文件,如文档中所述:

public function boot()
{
    $this->publishes([
        __DIR__ . '/config/config.php' =>   config_path('/packages/longestdrive/googlecal/googlecal.php'),
    ]);

现在我正尝试使用以下方法访问此配置中的项目:

config('googlecal.client_id');

然而,这会返回null

如果我只是这样做:config()我得到一个完整的配置数组,可以看到我的包配置文件。

如果我这样做:config('longestdrive.googlecal.googlecal.client_id')我可以访问该变量。

在L4.2中,我不需要有效地添加变量的完整路径。

我是否错过了让我能够做到的事情:config('googlecal.client_id')

由于

2 个答案:

答案 0 :(得分:1)

您必须在ServiceProvider中合并配置文件

/**
 * Register the service provider.
 */
public function register()
{
    $this->app->bind('laravel-db-localization', function ($app) {
        return new LaravelDbLocalization();
    });

    // Load the config file
    $this->mergeConfigFrom(__DIR__.'/config/laravel-db-localization.php', 'laravel-db-localization');
}

答案 1 :(得分:0)

可能你应该运行“php artisan config:cache”,它适用于我:)

相关问题