ldc-agis/database/factories/ProductFactory.php
2023-10-23 12:24:37 +02:00

77 lines
2.7 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' => 'Energie en Kj',
'value' => fake()->randomFloat(2, 0, 70)
],
'energyKcal' => [
'label' => 'Energie en kcal',
'value' => fake()->randomFloat(2, 0, 70)
],
'fat' => [
'label' => 'Matières grasses',
'value' => fake()->randomFloat(2, 0, 70)
],
'saturated-fat' => [
'label' => 'dont acides gras saturés',
'value' => fake()->randomFloat(2, 0, 70)
],
'carbohydrate' => [
'label' => 'Glucides',
'value' => fake()->randomFloat(2, 0, 70)
],
'sugar' => [
'label' => 'dont sucres',
'value' => fake()->randomFloat(2, 0, 70)
],
'proteins' => [
'label' => 'Protéines',
'value' => fake()->randomFloat(2, 0, 70)
],
'salt' => [
'label' => 'Sel',
'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,
];
}
}