feat(阶段三): 添加知识库模型和迁移

- 创建 knowledge_bases 表迁移
- 创建 KnowledgeBase 模型
- 创建 KnowledgeBaseFactory 工厂类
- 支持与终端的多对多关联关系
This commit is contained in:
2026-03-09 10:59:20 +08:00
parent 29f72eb65e
commit 333034d2f1
3 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?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');
}
}