feat(阶段三): 添加知识库模型和迁移
- 创建 knowledge_bases 表迁移 - 创建 KnowledgeBase 模型 - 创建 KnowledgeBaseFactory 工厂类 - 支持与终端的多对多关联关系
This commit is contained in:
36
app/Models/KnowledgeBase.php
Normal file
36
app/Models/KnowledgeBase.php
Normal 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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user