Files
KnowledgeBase/app/Models/KnowledgeBase.php
lizhuoran 333034d2f1 feat(阶段三): 添加知识库模型和迁移
- 创建 knowledge_bases 表迁移
- 创建 KnowledgeBase 模型
- 创建 KnowledgeBaseFactory 工厂类
- 支持与终端的多对多关联关系
2026-03-09 10:59:20 +08:00

37 lines
790 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');
}
}