59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\Concentration;
|
|
use App\Models\Brand;
|
|
use App\Models\Perfume;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
class PerfumeFactory extends Factory
|
|
{
|
|
protected $model = Perfume::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
$name = $this->faker->unique()->words(2, true);
|
|
|
|
return [
|
|
'brand_id' => Brand::factory(),
|
|
'name' => Str::title($name),
|
|
'slug' => Str::slug($name.'-'.$this->faker->unique()->randomNumber()),
|
|
'sku' => strtoupper($this->faker->unique()->bothify('PER-#####')),
|
|
'concentration' => $this->faker->randomElement(Concentration::cases()),
|
|
'cost_price' => $this->faker->numberBetween(50000, 250000),
|
|
'sale_price' => $this->faker->numberBetween(80000, 400000),
|
|
];
|
|
}
|
|
|
|
public function withNotes(): Factory
|
|
{
|
|
return $this->state(fn () => [
|
|
'base_notes' => $this->faker->words(3, true),
|
|
'middle_notes' => $this->faker->words(3, true),
|
|
'top_notes' => $this->faker->words(3, true),
|
|
]);
|
|
}
|
|
|
|
public function withDescription(): Factory
|
|
{
|
|
return $this->state(fn () => ['description' => $this->faker->paragraph()]);
|
|
}
|
|
|
|
public function withoutBrand(): Factory
|
|
{
|
|
return $this->state(fn () => ['brand_id' => null]);
|
|
}
|
|
|
|
public function extrait(): Factory
|
|
{
|
|
return $this->state(fn () => ['concentration' => Concentration::EXTRAIT_DE_PERFUME]);
|
|
}
|
|
|
|
public function eauDeParfum(): Factory
|
|
{
|
|
return $this->state(fn () => ['concentration' => Concentration::EAU_DE_PERFUME]);
|
|
}
|
|
}
|