2017-12-10 11:21:49 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Model;
|
|
|
|
|
2018-03-19 09:37:35 +08:00
|
|
|
/**
|
|
|
|
* Class Setting
|
|
|
|
* @property string id
|
|
|
|
* @property string name
|
|
|
|
* @property string key
|
|
|
|
* @property string value
|
|
|
|
* @property string group
|
|
|
|
* @property string type
|
|
|
|
* @property string options
|
|
|
|
* @property string description
|
|
|
|
* @package App\Models
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Setting extends Model
|
2017-12-10 11:21:49 +08:00
|
|
|
{
|
|
|
|
public $table = 'settings';
|
2018-01-01 01:09:56 +08:00
|
|
|
public $incrementing = false;
|
2017-12-10 11:21:49 +08:00
|
|
|
|
|
|
|
public $fillable = [
|
|
|
|
'name',
|
|
|
|
'key',
|
|
|
|
'value',
|
|
|
|
'group',
|
|
|
|
'type',
|
|
|
|
'options',
|
|
|
|
'description',
|
|
|
|
];
|
|
|
|
|
2018-01-04 12:04:51 +08:00
|
|
|
public static $rules = [
|
|
|
|
'name' => 'required',
|
|
|
|
'key' => 'required',
|
|
|
|
'group' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $key
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2018-01-01 01:19:18 +08:00
|
|
|
public static function formatKey($key)
|
|
|
|
{
|
|
|
|
return str_replace('.', '_', strtolower($key));
|
|
|
|
}
|
|
|
|
|
2018-01-04 12:04:51 +08:00
|
|
|
/**
|
2018-03-19 09:37:35 +08:00
|
|
|
* Force formatting the key
|
|
|
|
* @param $id
|
2018-01-04 12:04:51 +08:00
|
|
|
*/
|
2018-03-19 09:37:35 +08:00
|
|
|
public function setIdAttribute($id): void
|
2018-01-01 01:09:56 +08:00
|
|
|
{
|
2018-03-19 09:37:35 +08:00
|
|
|
$id = strtolower($id);
|
|
|
|
$this->attributes['id'] = self::formatKey($id);
|
2018-01-01 01:09:56 +08:00
|
|
|
}
|
2018-01-07 05:41:23 +08:00
|
|
|
|
|
|
|
/**
|
2018-03-19 09:37:35 +08:00
|
|
|
* Set the key to lowercase
|
|
|
|
* @param $key
|
2018-01-07 05:41:23 +08:00
|
|
|
*/
|
2018-03-19 09:37:35 +08:00
|
|
|
public function setKeyAttribute($key): void
|
2018-01-07 05:41:23 +08:00
|
|
|
{
|
2018-03-19 09:37:35 +08:00
|
|
|
$this->attributes['key'] = strtolower($key);
|
|
|
|
}
|
2017-12-10 11:21:49 +08:00
|
|
|
}
|