Passed
Push — dev6 ( 5ebf7f...1a3248 )
by Ron
16:55
created

AppSettingsTrait::saveArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace App\Traits;
4
5
use App\Models\AppSettings;
6
7
/**
8
 *  AllowTrait only has one function to check permission for the policies
9
 */
10
trait AppSettingsTrait
11
{
12
    //  Save an individual setting into the database so that it can be modified from the hard coded setting
13
    protected function saveSettings($key, $value)
14
    {
15
        AppSettings::firstOrCreate(
16
            ['key'   => $key],
17
            ['value' => $value]
18
        )->update(['value' => $value]);
19
    }
20
21
    //  Array must be in the form of ['key' => 'value] in order to be properly updated
22
    protected function saveArray($settingArray)
23
    {
24
        foreach($settingArray as $key => $value)
25
        {
26
            $this->saveSettings($key, $value);
27
        }
28
    }
29
}
30