- 创建 knowledge_bases 表迁移 - 创建 KnowledgeBase 模型 - 创建 KnowledgeBaseFactory 工厂类 - 支持与终端的多对多关联关系
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\KnowledgeBase;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\KnowledgeBase>
|
|
*/
|
|
class KnowledgeBaseFactory extends Factory
|
|
{
|
|
protected $model = KnowledgeBase::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'name' => $this->faker->words(3, true),
|
|
'description' => $this->faker->sentence(),
|
|
'status' => $this->faker->randomElement(['active', 'inactive']),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 指定知识库为激活状态
|
|
*/
|
|
public function active(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'status' => 'active',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 指定知识库为非激活状态
|
|
*/
|
|
public function inactive(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'status' => 'inactive',
|
|
]);
|
|
}
|
|
}
|