62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use App\Models\Forum;
|
|
use Faker\Factory as FakerFactory;
|
|
|
|
class ForumSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$faker = FakerFactory::create();
|
|
|
|
for ($categoryIndex = 1; $categoryIndex <= 5; $categoryIndex += 1) {
|
|
$category = Forum::create([
|
|
'name' => ucfirst($faker->words(2, true)),
|
|
'description' => $faker->sentence(),
|
|
'type' => 'category',
|
|
'parent_id' => null,
|
|
'position' => $categoryIndex,
|
|
]);
|
|
|
|
$subcategoryCount = $faker->numberBetween(1, 5);
|
|
for ($subIndex = 1; $subIndex <= $subcategoryCount; $subIndex += 1) {
|
|
$subcategory = Forum::create([
|
|
'name' => ucfirst($faker->words(2, true)),
|
|
'description' => $faker->sentence(),
|
|
'type' => 'category',
|
|
'parent_id' => $category->id,
|
|
'position' => $subIndex,
|
|
]);
|
|
|
|
$subForumCount = $faker->numberBetween(1, 5);
|
|
for ($forumIndex = 1; $forumIndex <= $subForumCount; $forumIndex += 1) {
|
|
Forum::create([
|
|
'name' => ucfirst($faker->words(3, true)),
|
|
'description' => $faker->sentence(),
|
|
'type' => 'forum',
|
|
'parent_id' => $subcategory->id,
|
|
'position' => $forumIndex,
|
|
]);
|
|
}
|
|
}
|
|
|
|
$forumCount = $faker->numberBetween(3, 10);
|
|
for ($forumIndex = 1; $forumIndex <= $forumCount; $forumIndex += 1) {
|
|
Forum::create([
|
|
'name' => ucfirst($faker->words(3, true)),
|
|
'description' => $faker->sentence(),
|
|
'type' => 'forum',
|
|
'parent_id' => $category->id,
|
|
'position' => $subcategoryCount + $forumIndex,
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|