Support the ongoing development of Laravel.io →
posted 7 years ago
Last updated 2 years ago.
0

You can merge your package default config with the one published by the user

https://laravel.com/docs/5.5/packages#configuration

In your package service provider:

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

/**
 * Perform post-registration booting of services.
 *
 * @return void
 */
public function boot()
{
    $this->publishes([
        __DIR__.'/config.php' => config_path('awesome_package.php'),
    ]);
}

Then in your package you can simply call config('awesome_package.my_option') and it will take the user's published value if present, otherwise it will take your package config default value.

This way you don't force any publishing but you provide a way to override values if needed

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.