Run Vendor:publish error when using helper method config in Laravel development package

Source: Internet
Author: User
Self-developed a package, which uses provider to register the service, but it is useful to the Config () method to get the configuration, the problem is that the config file has not been publish, I feel that my thinking is not right ah.
The code is as follows:

class SuperViewConfigProvider extends ServiceProvider{    /**     * Bootstrap any application services.     *     * @return void     */    public function boot()    {        // Publish the config file to         $this->publishes([            __DIR__.'/../../config/config.php' => config_path('superview.php'),        ]);    }}
  class Superviewmodelprovider extends serviceprovider{/** * indicates if     Loading of the provider is deferred.    * * @var BOOL */protected $defer = true;     /** * Register any application services. * * @return void */Public Function Register () {//Get config and then bind automaticly $models        = Array_keys (config (' superview.models ')); foreach ($models as $model) {$this->app->singleton (' Superview.model_prefix '). $model, Function ($            APP) use ($models, $model) {return new $models [$model];        });     }}/** * Get the services provided by the provider. * * @return Array */Public function provides () {return Array_map (function ($value) {Retu RN config (' Superview.model_prefix ').        $value;    }, Array_keys (config (' superview.models '))); }}

Then I run: PHP artisan vendor:publish--provider= "Superviewproviderssuperviewconfigprovider"
You will get an error saying that the config content does not exist.

Reply content:

Self-developed a package, which uses provider to register the service, but it is useful to the Config () method to get the configuration, the problem is that the config file has not been publish, I feel that my thinking is not right ah.
The code is as follows:

class SuperViewConfigProvider extends ServiceProvider{    /**     * Bootstrap any application services.     *     * @return void     */    public function boot()    {        // Publish the config file to         $this->publishes([            __DIR__.'/../../config/config.php' => config_path('superview.php'),        ]);    }}
  class Superviewmodelprovider extends serviceprovider{/** * indicates if     Loading of the provider is deferred.    * * @var BOOL */protected $defer = true;     /** * Register any application services. * * @return void */Public Function Register () {//Get config and then bind automaticly $models        = Array_keys (config (' superview.models ')); foreach ($models as $model) {$this->app->singleton (' Superview.model_prefix '). $model, Function ($            APP) use ($models, $model) {return new $models [$model];        });     }}/** * Get the services provided by the provider. * * @return Array */Public function provides () {return Array_map (function ($value) {Retu RN config (' Superview.model_prefix ').        $value;    }, Array_keys (config (' superview.models '))); }}

Then I run: PHP artisan vendor:publish--provider= "Superviewproviderssuperviewconfigprovider"
You will get an error saying that the config content does not exist.

In the provider register method, the first call is mergeConfigFrom :

$this->mergeConfigFrom(__DIR__.'/../../config/config.php', 'superview');

It means to base the configuration file in your package, then merge the configuration under the user's app directory, and finally get your superview configuration, and set it in the current config store.

You're going to write ServiceProvider it. Don't you check to see if this file exists?

__DIR__.'/../../config/config.php

I'm not sure if I can use config here before I release config.

public function provides(){        return array_map(function($value) {            return config('superview.model_prefix') . $value;        }, array_keys(config('superview.models')));}
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.