ldc-nature-and-respect/database/factories/ProductFactory.php
2023-04-25 13:42:16 +00:00

62 lines
1.7 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\Products\CertificationsEnum;
use App\Models\Product;
use App\Models\Range;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends Factory<\App\Models\Product>
*/
final class ProductFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Product::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition(): array
{
$label = fake()->unique()->word;
$list = ['en' => []];
for ($jj = 1; $jj <= 6; $jj++) {
array_push($list['en'], [
"value" => fake()->unique()->words(\rand(2, 8), true)
]);
}
$nutritionnal_values = ['en' => []];
for ($jj = 1; $jj <= 9; $jj++) {
array_push($nutritionnal_values['en'], [
"label" => fake()->unique()->words(\rand(2, 8), true),
"value" => fake()->unique()->words(2, true)
]);
}
return [
'seo_title' => fake()->word,
'seo_description' => fake()->text,
'label' => $label,
'slug' => Str::slug($label),
'description' => fake()->word,
'picture_alt' => fake()->word,
'picture_title' => fake()->word,
'certifications' => [\collect(CertificationsEnum::cases())->random()],
'nutritionnal_values' => $nutritionnal_values,
'list' => $list,
'status' => fake()->boolean(75),
'range_id' => fake()->randomElement(Range::pluck('id')),
];
}
}