2017-12-10 11:21:49 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2017-12-26 05:19:34 +08:00
|
|
|
class Setting extends BaseModel
|
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
|
|
|
/**
|
|
|
|
* Callbacks
|
|
|
|
*/
|
2018-01-01 01:09:56 +08:00
|
|
|
protected static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
static::creating(function (Setting $model) {
|
|
|
|
if (!empty($model->id)) {
|
2018-01-01 01:19:18 +08:00
|
|
|
$model->id = Setting::formatKey($model->id);
|
2018-01-01 01:09:56 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-01-07 05:41:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Override the casting mechanism
|
|
|
|
* @param string $key
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
/*protected function getCastType($key)
|
|
|
|
{
|
|
|
|
if ($key === 'value' && !empty($this->type)) {
|
|
|
|
return $this->type;
|
|
|
|
} else {
|
|
|
|
return parent::getCastType($key);
|
|
|
|
}
|
|
|
|
}*/
|
2017-12-10 11:21:49 +08:00
|
|
|
}
|