2017-12-10 11:21:49 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Model;
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-03-19 09:37:35 +08:00
|
|
|
/**
|
|
|
|
* @property string id
|
|
|
|
* @property string name
|
|
|
|
* @property string key
|
|
|
|
* @property string value
|
|
|
|
* @property string group
|
|
|
|
* @property string type
|
|
|
|
* @property string options
|
|
|
|
* @property string description
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Setting extends Model
|
2017-12-10 11:21:49 +08:00
|
|
|
{
|
|
|
|
public $table = 'settings';
|
2019-09-13 20:05:02 +08:00
|
|
|
|
|
|
|
protected $keyType = 'string';
|
2018-01-01 01:09:56 +08:00
|
|
|
public $incrementing = false;
|
2017-12-10 11:21:49 +08:00
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
protected $fillable = [
|
2017-12-10 11:21:49 +08:00
|
|
|
'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
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-01-04 12:04:51 +08:00
|
|
|
* @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
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-19 09:37:35 +08:00
|
|
|
* @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
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-19 09:37:35 +08:00
|
|
|
* @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
|
|
|
}
|