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.
Inregister
CallmergeConfigFrom
:
$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 writeServiceProvider
So 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')));}