You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
937 B

<?php
namespace App\Models;
use Illuminate\Support\Facades\Cache;
class AppointmentConfig extends SoftDeletesModel
{
protected $guarded = ['id', 'value', 'room', 'door', 'remark'];
protected $casts = ['file_ids' => 'json'];
protected $appends = ['files'];
public function getFilesAttribute($value)
{
if (empty($this->file_ids)) return [];
return Upload::whereIn('id', $this->file_ids)->get();
}
/**
* 通过键名获取值
*/
public static function getValueByKey($key)
{
$config = Cache::remember('appointment_config_array', 300, function () {
return self::pluck('value', 'key')->toArray();
});
if (isset($config[$key])) {
return $config[$key];
}
return null;
}
public function appointmentType()
{
return $this->hasOne(AppointmentType::class, 'id', 'appointment_type_id');
}
}