Completed
Pull Request — develop (#57)
by Tony
07:09
created

DbConfig::scopeKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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
    /**
51
     * Define fillable fields
52
     *
53
     * @var array
54
     */
55
    protected $fillable = ['config_name', 'config_value'];
56
57
    public function scopeKey($query, $key)
58
    {
59
        return $query->where('config_name', 'LIKE', $key . '%');
60
    }
61
62
    public function scopeExactKey($query, $key)
63
    {
64
        return $query->where('config_name', $key);
65
    }
66
67
    /**
68
     * Indicates if the model should be timestamped.
69
     *
70
     * @var bool
71
     */
72
    public $timestamps = false;
73
74
    // ---- Accessors/Mutators ----
75
76
    public function getConfigValueAttribute($value)
77
    {
78
        if (!empty($value)) {
79
            return unserialize($value);
80
        }
81
        return $value;
82
    }
83
84
    public function setConfigValueAttribute($value)
85
    {
86
        $this->attributes['config_value'] = serialize($value);
87
    }
88
}
89