47 lines
1004 B
PHP
47 lines
1004 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class KnowledgeBase extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
/**
|
|
* 可批量赋值的属性
|
|
*
|
|
* @var array<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'description',
|
|
'status',
|
|
];
|
|
|
|
/**
|
|
* 获取关联的终端
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function terminals()
|
|
{
|
|
return $this->belongsToMany(Terminal::class, 'terminal_knowledge_bases')
|
|
->withPivot('priority')
|
|
->withTimestamps()
|
|
->orderBy('priority');
|
|
}
|
|
|
|
/**
|
|
* 获取知识库下的文档
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function documents()
|
|
{
|
|
return $this->hasMany(Document::class);
|
|
}
|
|
}
|