【问题标题】:use config file of custom package without publishing in Laravel 5.*使用自定义包的配置文件而不在 Laravel 5 中发布。*
【发布时间】:2017-10-19 03:40:38
【问题描述】:

我的 Laravel 自定义包有一个 config 文件。

目前我正在使用 自定义包的 config 文件,方法是按照 docs 中的说明进行发布。

我只是想澄清一下,有没有办法使用自定义包的 config 文件而不在 Laravel 5.*

中发布它

【问题讨论】:

    标签: laravel laravel-5 package config publish


    【解决方案1】:

    解决了。

    这是我使用的代码。

    public function register()
        {
    
            if ($this->app['config']->get('custom_package') === null) {
                $this->app['config']->set('custom_package', require __DIR__.'/../Config/config.php');
            }
    

    在 自定义包 的 ServiceProvider 中。

    【讨论】:

      【解决方案2】:

      你可以使用你的包的ServiceProvider的mergeConfigFrom方法

      /**
       * Register bindings in the container.
       *
       * @return void
       */
      public function register()
      {
          $this->mergeConfigFrom(
              __DIR__.'/path/to/config/courier.php', 'courier'
          );
      }
      

      【讨论】:

        猜你喜欢
        • 2018-09-15
        • 1970-01-01
        • 2018-12-21
        • 1970-01-01
        • 1970-01-01
        • 2015-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多