Settings

LAP allows you to easily manage app-wide settings in the database. All settings are stored in key value pairs and are accessible via the Laravel config() helper function.

Creating Settings

To create a new setting, simply insert a new record into the database:

app(config('lap.models.setting'))->create([
    'key' => 'example',
    'value' => 'Hello World',
]);

Updating Settings

Updating settings is as simple as using the update() method on settings with a specific key:

app(config('lap.models.setting'))->where('key', 'example')->update([
    'value' => 'Hello World Updated',
]);

Using Settings

Once your settings exist in the database, they can easily be retrieved and used with the config() helper:

$example_setting = config('settings.example');

Note the use of example here, where example is the key for the setting. This works for any setting in the database.

The Settings Form

You'll want to create inputs for all of your settings in the database. This can be done by editing the settings form located in views/vendor/lap/backend/settings.blade.php. This is the form which displays when you click on Settings in the admin panel.

Of course, along with editing the blade template, you may also want to pass certain values to it via the controller, and update validation rules. This can be done by modifying the settingsForm and settingsRules methods located in App\Http\Controllers\Admin\Backend. These methods control displaying and validating settings via the form.

Note that by default, LAP will automatically save all settings submitted via the settings form by using the input names as keys. If you require different behaviour, you will need to override the settings method in the BackendController.