phpvms/app/Models/Setting.php

71 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use App\Contracts\Model;
/**
* @property string id
* @property string name
* @property string key
* @property string value
* @property string group
* @property string type
* @property string options
* @property string description
*/
class Setting extends Model
{
public $table = 'settings';
protected $keyType = 'string';
public $incrementing = false;
2018-03-21 08:40:19 +08:00
protected $fillable = [
'name',
'key',
'value',
'group',
'type',
'options',
'description',
];
public static $rules = [
'name' => 'required',
'key' => 'required',
'group' => 'required',
];
/**
* @param $key
2018-08-27 00:40:04 +08:00
*
* @return mixed
*/
2018-01-01 01:19:18 +08:00
public static function formatKey($key)
{
return str_replace('.', '_', strtolower($key));
}
/**
* Force formatting the key
2018-08-27 00:40:04 +08:00
*
* @param $id
*/
public function setIdAttribute($id): void
{
$id = strtolower($id);
$this->attributes['id'] = self::formatKey($id);
}
/**
* Set the key to lowercase
2018-08-27 00:40:04 +08:00
*
* @param $key
*/
public function setKeyAttribute($key): void
{
$this->attributes['key'] = strtolower($key);
}
}