Passed
Push — master ( 75ec53...0424dc )
by Iman
04:49
created

SettingRepo::table()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\SettingModule;
4
5
class SettingRepo
6
{
7
    public static function getSetting($name)
8
    {
9
        return cache()->rememberForever('crudbooster_setting_'.$name, function () use($name) {
10
            return self::table()->where('name', $name)->first()->content;
11
        });
12
    }
13
14
    public static function resetSettings($data)
15
    {
16
        foreach ($data as $row) {
17
            $count = self::table()->where('name', $row['name'])->count();
18
            if (! $count) {
19
                self::table()->insert($row);
20
                continue;
21
            }
22
            if ($count > 1) {
23
                $rowId = self::table()->where('name', $row['name'])->orderby('id', 'asc')->first()->id;
24
                self::table()->where('name', $row['name'])->where('id', '!=', $rowId)->delete();
25
            }
26
        }
27
    }
28
29
    /**
30
     * @return mixed
31
     */
32
    private static function table()
33
    {
34
        return \DB::table('cms_settings');
35
    }
36
}