ldc-agis/database/factories/ProductFactory.php
Jérémy Munsch 3db48686ee
Closes #70
2024-03-05 11:36:09 +01:00

77 lines
2.8 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\Products\CookingModeEnum;
use App\Models\Range;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class ProductFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
$title = fake()->sentence();
$nutritionnal_values = [
'energyKj' => [
'label' => 'ÉNERGIE (kJ)',
'value' => fake()->randomFloat(2, 0, 70)
],
'energyKcal' => [
'label' => 'ÉNERGIE (kcal)',
'value' => fake()->randomFloat(2, 0, 70)
],
'fat' => [
'label' => 'MATIÈRES GRASSES (g)',
'value' => fake()->randomFloat(2, 0, 70)
],
'saturated-fat' => [
'label' => 'ACIDES GRAS SATURÉS (g)',
'value' => fake()->randomFloat(2, 0, 70)
],
'carbohydrate' => [
'label' => 'GLUCIDES (g)',
'value' => fake()->randomFloat(2, 0, 70)
],
'sugar' => [
'label' => 'SUCRES (g)',
'value' => fake()->randomFloat(2, 0, 70)
],
'proteins' => [
'label' => 'PROTÉINES (g)',
'value' => fake()->randomFloat(2, 0, 70)
],
'salt' => [
'label' => 'SEL (g)',
'value' => fake()->randomFloat(2, 0, 70)
],
];
return [
'seo_title' => fake()->word(),
'seo_description' => fake()->text(160),
'title' => $title,
'slug' => Str::slug($title),
'subtitle' => fake()->sentence(),
'picture_thumbnail_alt' => fake()->sentence(),
'picture_thumbnail_title' => fake()->sentence(),
'picture_ambiance_alt' => fake()->sentence(),
'picture_ambiance_title' => fake()->sentence(),
'picture_packshot_alt' => fake()->sentence(),
'picture_packshot_title' => fake()->sentence(),
'description' => \clean(\fake()->randomHtml(6, 7)),
'cooking_mode' => \collect(CookingModeEnum::cases())->random(),
'cooking_advice' => \clean(\fake()->randomHtml(6, 7)),
'ingredients' => \clean(\fake()->randomHtml(6, 7)),
'nutritionnal_values' => json_encode($nutritionnal_values),
'published' => fake()->boolean(75),
'range_id' => Range::all()->random()->id,
];
}
}