65 lines
1.9 KiB
PHP
65 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\Shop\SellItemsType;
|
|
use App\Models\SellItem;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SellItem>
|
|
*/
|
|
class SellItemFactory extends Factory
|
|
{
|
|
|
|
protected $model = SellItem::class;
|
|
|
|
#[\Override]
|
|
protected function withFaker()
|
|
{
|
|
return class_exists(\Faker\Generator::class) ? parent::withFaker() : null;
|
|
}
|
|
|
|
public function definition(): array
|
|
{
|
|
return $this->faker !== null
|
|
? $this->definitionWithFaker()
|
|
: $this->definitionStatic();
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function definitionWithFaker(): array
|
|
{
|
|
return [
|
|
'name' => fake()->words(fake()->numberBetween(1, 2), true),
|
|
'picture' => '',
|
|
'picture_alt' => fake()->sentence(),
|
|
'picture_title' => fake()->sentence(),
|
|
'price' => fake()->numberBetween(1, 100),
|
|
'arcadia_weight' => fake()->numberBetween(1, 100),
|
|
'arcadia_id' => fake()->unique()->numberBetween(100, 500),
|
|
'order' => 1,
|
|
'type' => fake()->randomElement(SellItemsType::cases()),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function definitionStatic(): array
|
|
{
|
|
return [
|
|
'name' => 'Article Démo Test',
|
|
'picture' => '',
|
|
'picture_alt' => 'Image descriptive article démo',
|
|
'picture_title' => 'Titre image démo',
|
|
'price' => 29.99,
|
|
'arcadia_weight' => 500,
|
|
'arcadia_id' => 101,
|
|
'order' => 1,
|
|
'type' => SellItemsType::cases()[0] ?? 'standard',
|
|
];
|
|
}
|
|
}
|