44 lines
937 B
PHP
44 lines
937 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\StorageFile;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
|
|
/**
|
|
* 字典表
|
|
*/
|
|
class Keyword extends Model
|
|
{
|
|
use Filterable, HasDateTimeFormatter;
|
|
|
|
protected $fillable = ['id', 'name', 'key', 'value', 'parent_id', 'type_key', 'path', 'sort', 'level', 'options', 'image', 'description', 'content'];
|
|
|
|
protected $casts = [
|
|
'options' => 'array',
|
|
'image' => StorageFile::class,
|
|
];
|
|
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(static::class, 'parent_id');
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->hasMany(static::class, 'parent_id');
|
|
}
|
|
|
|
public function illnessTypeRecords()
|
|
{
|
|
return $this->hasMany(PatientRecord::class, 'illness_type_id');
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
return $q->orderByDesc('sort');
|
|
}
|
|
}
|