# 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:

<div align="left"><img src="https://582218703-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0JvlXkNR9xWhK_ij0j%2F-M23zGojsYoAlQ_hfiiM%2F-M24-y73Ph5O-LFpivPk%2Fsettings_config.png?alt=media&#x26;token=5d4feb69-c1c2-4693-adf6-f19740e9591b" alt=""></div>

Say you want to create a new group (or section) of settings in the admin panel:

```php
'My New Section' => [ // Text for the header 
    // Your fields here
]
```

Each array inside represents a field:

```php
[
    'name'          => 'my_setting',
    'label'         => 'My Setting',
    'field_type'    => 'text',
    'icon'          => 'ni ni-email-83',
    'info_text'     => 'This is my new setting.',
    'required'      => true,
    'content'       => null
],
```

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

    ```php
    // For field_type => 'select'
    'content'  => [
        'value_1'   => 'First option',
        'value_2'   => 'Second option'
    ],

    // For field_type => 'radio'
    'content'  => [
        [
            'label'    => 'First option',
            'value'    => 1
        ],
        [
            'label'    => 'Second option',
            'value'    => 2
        ],
    ],

    // For field_type => 'toggle' or 'checkbox'
    'content' => 'active',
    ```

Here is a full example for a new field in settings:

```php
// config/hotcoffee/settings.php

'fields'  => [
    
    // Some section
    'My New Section' => [
        
        // My custom setting
        [
            'name'          => 'my_setting',
            'label'         => 'My Setting',
            'field_type'    => 'select',
            'icon'          => 'ni ni-email-83',
            'info_text'     => 'This is my new setting.',
            'required'      => true,
            'content'       => [
                'value_1'   => 'This is value 1',
                'value_2'   => 'This is value 2'
            ]
        ] // End custom setting
        
    ], // end "some section"
    
...
```

This will be the HTML output in the template:

```php
<div class="col-md-12 form-header text-uppercase">
    Section name / header text
</div>

<div class="row">
    <div class="col-md-12">
        <div class="form-group focused">
            <label class="form-control-label" for="input-my_setting">
                My Setting
                <span class="text-danger">*</span>  
                <small class="text-primary">setting('my_setting')</small>
            </label>
    
            <select id="input-my_setting" class="form-control form-control-alternative no-border-radius" name="my_setting">
                <option value="value_1">This is value 1</option>
                <option value="value_2">This is value 2</option>
            </select>
        </div>
    </div>
    <div class="col-lg-12 info-div">
        This is my new setting.
    </div>
</div>
```

And what you see in Settings:

<div align="left"><img src="https://582218703-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0JvlXkNR9xWhK_ij0j%2F-M245niCGV8fv2kcGRqM%2F-M249MAc4e7WqTiEIYQT%2Fsetting_new_setting.png?alt=media&#x26;token=e011d64f-7e9c-4b18-8906-f987e9d20896" alt=""></div>

All the settings are stored in `storage/app/settings.json`.

{% hint style="success" %}
Need to easily store some values in a json file? Check this package [https://github.com/spatie/valuestore](https://github.com/spatie/valuestore)
{% endhint %}
