Files

61 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2018-05-09 08:05:17 -05:00
<?php
/**
* Config.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2018 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace App\Models;
class Config extends BaseModel
{
public $timestamps = false;
protected $table = 'config';
public $primaryKey = 'config_id';
2018-05-09 08:05:17 -05:00
protected $fillable = [
'config_name',
'config_value',
];
2019-10-06 21:51:22 +00:00
protected $casts = [
'config_default' => 'array'
];
2018-05-09 08:05:17 -05:00
// ---- Accessors/Mutators ----
2018-05-09 08:05:17 -05:00
public function getConfigValueAttribute($value)
{
2019-11-09 13:10:44 +00:00
return json_decode($value, true);
2018-05-09 08:05:17 -05:00
}
public function setConfigValueAttribute($value)
{
2019-10-06 21:51:22 +00:00
$this->attributes['config_value'] = json_encode($value, JSON_UNESCAPED_SLASHES);
2018-05-09 08:05:17 -05:00
}
// ---- Query Scopes ----
public function scopeWithChildren($query, $name)
{
return $query->where('config_name', $name)
->orWhere('config_name', 'like', "$name.%");
}
2018-05-09 08:05:17 -05:00
}