- Admin Interface
- How It Works
- Overwrite Bindings
The configs component is a very powerful functionality that allows you to quickly overwrite static config values in your application.
In order to provide you with a complex crud functionality inside the admin, the configs crud implements the following out of the box:
Before going deeper, you should know that there's already a section in the admin from where you can manage all your settings.
You can find the configs section inside Admin -> System Settings -> Configs.
Feel free to explore all available options this section offers.
How It Works
First of all, let's understand the workflow behind configs.
- Enable config overwrites by updating your .env variable
- Define the config keys that can be overwritten from the admin
- Create custom config values for your defined config keys
- Apply the middleware to actually modify the config values at runtime
Let's see how you can setup custom config values for your configuration keys.
Set Available Config Keys
By default, if you were to try to add a config from inside the admin panel, you'll notice that you don't have any values to specify for the
Key select input, which is required.
The platform isn't capable of overwriting any config values by default. This is intentional, in order not to allow a client to accidentally overwrite a config value that isn't meant for overwriting.
Only config keys specified by the developer will be available for overwrite inside the admin.
To allow config keys to be overwritten, you should specify them inside the
config/varbox/config.php config file, specifically inside the
'keys' => [ 'app.name', 'app.url', 'app.locale', ],
After you've allowed the config keys, they'll appear in the admin when trying to add a custom config.
Overwrite Config Values
In order for the created config values from the admin to replace your default ones, inside your
app/Http/Kernel.php file, add the
Varbox\Middleware\OverwriteConfigs middleware to your entire
web middleware group.
/** * The application's route middleware groups. * * @var array */ protected $middlewareGroups = [ 'web' => [ ... \Varbox\Middleware\OverwriteConfigs::class ], ... ];
That's it! Now try and access a config whose value has been dynamically modified from the admin.
config('app.name'); // returns your custom value from the admin
The configs configuration file is located at
For more information on how you can customize the system settings components, please read the comments from their configuration files.
In your projects, you may stumble upon the need to modify the behavior of these classes, in order to fit your needs.
Varbox makes this possible via the
config/varbox/bindings.php configuration file. In that file, you'll find every customizable class the platform uses.
For more information on how the class binding works, please refer to the Custom Bindings documentation section.
The config classes available for binding overwrites are:
This class represents the config model.
This class is used for interactions with the "Admin -> System Settings -> Configs" section.
This class is used for validating any config when creating or updating.
This is the middleware modifying your config keys with the values assigned from the admin.
This class is used for applying the filtering logic.
This class is used for applying the sorting logic.