When you are writing a Laravel package, usually you need a config file.
Also, we will publish the config file in the “boot” method of the service provider.
Then, in the “register” method you can get the configuration and use it when you create the instance of “Facade”.

Let’s see a typical config file:

Usually, we can use both static and dynamic values for our keys. Regarding dynamic values, you know that we can use only the environment values because any database access is denied in this context.

So, I use the following workaround very easy to implement. First of all, I add a new key in my configuration file, for example, “config_controller”.

This new key will be a class which we can use to get either all or any. In the “register” method of my service provider, I’ll check this new key. If it exists, then I will use that controller to change my configuration.

In the configuration file you can use:


If the method name is not specified then “getConfig” will be used.
Let’s see a typical controller used to modify the configuration:

In the above code, we have modified only one key. Of course, you can change the whole configuration file.