1
0
Fork 0

Seed curated catalog data

This commit is contained in:
Henrik Hautakoski 2026-04-29 15:34:22 +02:00
parent ae93c7e1a6
commit 3b05a045ed
3 changed files with 611 additions and 30 deletions

View file

@ -2,9 +2,6 @@
namespace Database\Seeders;
use App\Models\Brand;
use App\Models\Category;
use App\Models\Product;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
@ -25,32 +22,10 @@ class DatabaseSeeder extends Seeder
'email' => 'test@example.com',
]);
$brands = Brand::factory(12)->create();
$this->call(CategorySeeder::class);
$allCategories = Category::query()->get();
$parentCategories = $allCategories->whereNull('parent_id')->values();
$childCategories = $allCategories->whereNotNull('parent_id')->values();
if ($allCategories->isEmpty()) {
return;
}
Product::factory(100)
->state(fn (): array => [
'category_id' => $childCategories->isNotEmpty()
? $childCategories->random()->id
: $allCategories->random()->id,
'brand_id' => $brands->random()->id,
])
->create();
Product::factory(30)
->state(fn (): array => [
'category_id' => $parentCategories->random()->id,
'brand_id' => $brands->random()->id,
])
->create();
$this->call([
BrandSeeder::class,
CategorySeeder::class,
ProductSeeder::class,
]);
}
}