Adding Settings
You can easily add more settings fields in config/hotcoffee/settings.php. However you will need to first publish this configuration file:
php artisan vendor:publish --tag=hotcoffee_config_settings
Inside of the "fields" array you can specify new sections and fields in those sections:
Say you want to create a new group (or section) of settings in the admin panel:
1
'My New Section' => [ // Text for the header
2
// Your fields here
3
]
Copied!
Each array inside represents a field:
1
[
2
'name' => 'my_setting',
3
'label' => 'My Setting',
4
'field_type' => 'text',
5
'icon' => 'ni ni-email-83',
6
'info_text' => 'This is my new setting.',
7
'required' => true,
8
'content' => null
9
],
Copied!
    name Keyword. The value of this setting will be called with settings('my_setting').
    label The label for the field.
    field_type The type of the field. Can be text, textarea, number, checkbox, radio, select and toggle.
    icon Icon code for the field.
    info_text This text will appear bellow the field. Use it to explain where/how the setting is used.
    required If true, required attribute will be added to the generated field.
    content Only needs to be declared when the field_type is one of checkbox, radio, select or toggle. Can be a string (for "toggle" and "checkbox") or array (for "radio" and "select).
      If the field_type is "select", then you can use the content to define the available options in the list (value and text of the option field).
      If field_type is "radio", then you can use the content to describe the label and value of each radio input.
      If field_type is "toggle", then you can use the content to declare the value of the input field.
      If field_type is "checkbox", then you can use the content to declare the value of the input field.
    1
    // For field_type => 'select'
    2
    'content' => [
    3
    'value_1' => 'First option',
    4
    'value_2' => 'Second option'
    5
    ],
    6
    7
    // For field_type => 'radio'
    8
    'content' => [
    9
    [
    10
    'label' => 'First option',
    11
    'value' => 1
    12
    ],
    13
    [
    14
    'label' => 'Second option',
    15
    'value' => 2
    16
    ],
    17
    ],
    18
    19
    // For field_type => 'toggle' or 'checkbox'
    20
    'content' => 'active',
    Copied!
Here is a full example for a new field in settings:
1
// config/hotcoffee/settings.php
2
3
'fields' => [
4
5
// Some section
6
'My New Section' => [
7
8
// My custom setting
9
[
10
'name' => 'my_setting',
11
'label' => 'My Setting',
12
'field_type' => 'select',
13
'icon' => 'ni ni-email-83',
14
'info_text' => 'This is my new setting.',
15
'required' => true,
16
'content' => [
17
'value_1' => 'This is value 1',
18
'value_2' => 'This is value 2'
19
]
20
] // End custom setting
21
22
], // end "some section"
23
24
...
Copied!
This will be the HTML output in the template:
1
<div class="col-md-12 form-header text-uppercase">
2
Section name / header text
3
</div>
4
5
<div class="row">
6
<div class="col-md-12">
7
<div class="form-group focused">
8
<label class="form-control-label" for="input-my_setting">
9
My Setting
10
<span class="text-danger">*</span>
11
<small class="text-primary">setting('my_setting')</small>
12
</label>
13
14
<select id="input-my_setting" class="form-control form-control-alternative no-border-radius" name="my_setting">
15
<option value="value_1">This is value 1</option>
16
<option value="value_2">This is value 2</option>
17
</select>
18
</div>
19
</div>
20
<div class="col-lg-12 info-div">
21
This is my new setting.
22
</div>
23
</div>
Copied!
And what you see in Settings:
All the settings are stored in storage/app/settings.json.
Need to easily store some values in a json file? Check this package https://github.com/spatie/valuestore
Last modified 1yr ago
Copy link