Custom Configs

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:

Admin Interface

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.

Configs List

How It Works

First of all, let's understand the workflow behind configs.

The Workflow

Usage

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 section.

'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

Configuration

The configs configuration file is located at config/varbox/config.php.

For more information on how you can customize the system settings components, please read the comments from their configuration files.

Overwrite Bindings

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:

Varbox\Models\Config

Found in config/varbox/bindings.php at models.config_model key.
This class represents the config model.

Varbox\Controllers\ConfigsController

Found in config/varbox/bindings.php at controllers.configs_controller key.
This class is used for interactions with the "Admin -> System Settings -> Configs" section.

Varbox\Requests\ConfigRequest

Found in config/varbox/bindings.php at form_requests.config_form_request key.
This class is used for validating any config when creating or updating.

Varbox\Middleware\OverwriteConfigs

Found in config/varbox/bindings.php at middleware.overwrite_configs_middleware key.
This is the middleware modifying your config keys with the values assigned from the admin.

Varbox\Filters\ConfigFilter

Found in config/varbox/bindings.php at filters.config_filter key.
This class is used for applying the filtering logic.

Varbox\Sorts\ConfigSort

Found in config/varbox/bindings.php at sorts.config_sort key.
This class is used for applying the sorting logic.