【问题标题】:laravel 5.1 access package config valueslaravel 5.1 访问包配置值
【发布时间】:2015-09-03 18:29:45
【问题描述】:

我正在 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')

谢谢

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    也许你应该运行“php artisan config:cache”,它对我有用:)

    【讨论】:

      【解决方案2】:

      您必须在 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');
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-07-13
        • 1970-01-01
        • 2016-03-16
        • 2015-11-07
        • 2017-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多