dress/database/factories/ProductFactory.php

50 lines
1.6 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\PriceType;
use App\Models\Product;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<Product>
*/
class ProductFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$types = ['Gamis', 'Dress', 'Tunik', 'Abaya', 'Hijab', 'Setelan', 'Blazer', 'Outer', 'Kaftan'];
$adjectives = ['Syari', 'Premium', 'Basic', 'Modern', 'Casual', 'Elegan', 'Mewah', 'Daily'];
$name = $this->faker->randomElement($types).' '.$this->faker->randomElement($adjectives).' '.$this->faker->firstNameFemale;
return [
'name' => $name,
'description' => $this->faker->paragraph,
'is_active' => $this->faker->boolean(80),
];
}
/**
* Configure the model factory.
*/
public function configure(): static
{
return $this->afterCreating(function (Product $product) {
$basePrice = $this->faker->numberBetween(5, 30) * 10000;
$product->prices()->createMany([
['price_type' => PriceType::PURCHASE->value, 'price' => $basePrice],
['price_type' => PriceType::DISTRIBUTOR->value, 'price' => $basePrice * 1.1],
['price_type' => PriceType::AGENT->value, 'price' => $basePrice * 1.25],
['price_type' => PriceType::RESELLER->value, 'price' => $basePrice * 1.4],
['price_type' => PriceType::RETAIL->value, 'price' => $basePrice * 1.6],
]);
});
}
}