- 创建 knowledge_bases 表迁移 - 创建 KnowledgeBase 模型 - 创建 KnowledgeBaseFactory 工厂类 - 支持与终端的多对多关联关系
37 lines
790 B
PHP
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');
|
|
}
|
|
}
|