Completed
Pull Request — develop (#57)
by Tony
06:31
created

DbConfig::getConfigValueAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
/*
3
 * Copyright (C) 2016 Tony Murray <[email protected]>
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
/**
18
 * DbConfig.php
19
 *
20
 * @package    LibreNMS
21
 * @author     Tony Murray <[email protected]>
22
 * @copyright  2016 Tony Murray
23
 * @license    @license http://opensource.org/licenses/GPL-3.0 GNU Public License v3 or later
24
 */
25
namespace App\Models;
26
27
use Illuminate\Database\Eloquent\Model;
28
29
/**
30
 * Class DbConfig
31
 *
32
 * @package App\Models
33
 */
34
class DbConfig extends Model
35
{
36
    /**
37
     * The table associated with the model.
38
     *
39
     * @var string
40
     */
41
    protected $table = 'config';
42
43
    /**
44
     * The primary key column name.
45
     *
46
     * @var string
47
     */
48
    protected $primaryKey = 'config_id';
49
50
    public function scopeKey($query, $key)
51
    {
52
        return $query->where('config_name', 'LIKE', $key . '%');
53
    }
54
55
    public function scopeExactKey($query, $key)
56
    {
57
        return $query->where('config_name', $key);
58
    }
59
60
    /**
61
     * Indicates if the model should be timestamped.
62
     *
63
     * @var bool
64
     */
65
    public $timestamps = false;
66
67
    // ---- Accessors/Mutators ----
68
69
    public function getConfigValueAttribute($value)
70
    {
71
        if (!empty($value)) {
72
            return unserialize($value);
73
        }
74
        return $value;
75
    }
76
77
    public function setConfigValueAttribute($value)
78
    {
79
        $this->attributes['config_value'] = serialize($value);
80
    }
81
}
82