When the helper method config is used in Laravel package development, the error message is returned when the vendor: publish command is run.

Source: Internet
Author: User
I developed a Package myself, in which Provider is used to register the service, but the config () method is used to obtain the configuration. The problem is that the config file has not been publish, I don't feel like I have a wrong idea. The code is as follows: {code ...} {code ...} then I run phparti... I developed a Package myself, in which Provider is used to register the service, but the config () method is used to obtain the configuration. The problem is that the config file has not been publish, I don't feel like I have a wrong idea.
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, then bind automaticly        $models = array_keys(config('superview.models'));        foreach ($models as $model) {            $this->app->singleton(config('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) {            return config('superview.model_prefix') . $value;        }, array_keys(config('superview.models')));    }}

Then I run: php artisan vendor: publish -- provider = "SuperViewProvidersSuperViewConfigProvider"
An error is reported, indicating that the config content does not exist.

Reply content:

I developed a Package myself, in which Provider is used to register the service, but the config () method is used to obtain the configuration. The problem is that the config file has not been publish, I don't feel like I have a wrong idea.
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, then bind automaticly        $models = array_keys(config('superview.models'));        foreach ($models as $model) {            $this->app->singleton(config('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) {            return config('superview.model_prefix') . $value;        }, array_keys(config('superview.models')));    }}

Then I run: php artisan vendor: publish -- provider = "SuperViewProvidersSuperViewConfigProvider"
An error is reported, indicating that the config content does not exist.

InregisterCallmergeConfigFrom:

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

It means that the configuration file in your package is used as the basis, and then the configuration under the user app directory is merged to get your superview configuration and set it in the current Config storage.

You will writeServiceProviderSo don't you check whether this file exists?

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

I'm not sure. Can I use config before releasing config?

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

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.