更新 app/Models/Keyword.php
parent
19ea8cfdf9
commit
9ace922048
|
|
@ -6,13 +6,14 @@ use App\Casts\StorageFile;
|
||||||
use EloquentFilter\Filterable;
|
use EloquentFilter\Filterable;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use App\Traits\HasDateTimeFormatter;
|
use App\Traits\HasDateTimeFormatter;
|
||||||
|
use App\Traits\TreePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字典表
|
* 字典表
|
||||||
*/
|
*/
|
||||||
class Keyword extends Model
|
class Keyword extends Model
|
||||||
{
|
{
|
||||||
use Filterable, HasDateTimeFormatter;
|
use Filterable, HasDateTimeFormatter, TreePath;
|
||||||
|
|
||||||
protected $fillable = ['id', 'name', 'key', 'value', 'parent_id', 'path', 'sort', 'level', 'options', 'image', 'description', 'content'];
|
protected $fillable = ['id', 'name', 'key', 'value', 'parent_id', 'path', 'sort', 'level', 'options', 'image', 'description', 'content'];
|
||||||
|
|
||||||
|
|
@ -20,19 +21,4 @@ class Keyword extends Model
|
||||||
'options' => 'array',
|
'options' => 'array',
|
||||||
'image' => StorageFile::class,
|
'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 scopeSort($q)
|
|
||||||
{
|
|
||||||
return $q->orderByDesc('sort');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue