73 lines
3.1 KiB
PHP
73 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\Products\NutriscoreEnum;
|
|
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()
|
|
{
|
|
$weight = fake()->randomNumber(3);
|
|
$energyKj = fake()->randomFloat(2, 0, 70);
|
|
$energyKcal = fake()->randomFloat(2, 0, 70);
|
|
$fat = fake()->randomFloat(2, 0, 70);
|
|
$saturated_fat = fake()->randomFloat(2, 0, 70);
|
|
$carbohydrate = fake()->randomFloat(2, 0, 70);
|
|
$sugar = fake()->randomFloat(2, 0, 70);
|
|
$proteins = fake()->randomFloat(2, 0, 70);
|
|
$salt = fake()->randomFloat(2, 0, 70);
|
|
|
|
$nutritionnal_values = [
|
|
'100g' => [
|
|
'label' => '100 g',
|
|
'energyKj' => $energyKj,
|
|
'energyKcal' => $energyKcal,
|
|
'fat' => $fat,
|
|
'saturated_fat' => $saturated_fat,
|
|
'carbohydrate' => $carbohydrate,
|
|
'sugar' => $sugar,
|
|
'proteins' => $proteins,
|
|
'salt' => $salt,
|
|
],
|
|
'self' => [
|
|
'label' => fake()->word() . ' ' . $weight . ' g',
|
|
'energyKj' => round($energyKj * $weight / 100, 2),
|
|
'energyKcal' => round($energyKcal * $weight / 100, 2),
|
|
'fat' => round($fat * $weight / 100, 2),
|
|
'saturated_fat' => round($saturated_fat * $weight / 100, 2),
|
|
'carbohydrate' => round($carbohydrate * $weight / 100, 2),
|
|
'sugar' => round($sugar * $weight / 100, 2),
|
|
'proteins' => round($proteins * $weight / 100, 2),
|
|
'salt' => round($salt * $weight / 100, 2),
|
|
],
|
|
];
|
|
|
|
$label = fake()->unique()->slug(3);
|
|
return [
|
|
'label' => Str::of($label)->replace('-', ' ')->title(),
|
|
'slug' => Str::slug($label),
|
|
'seo_title' => fake()->sentence(),
|
|
'seo_description' => fake()->sentence(),
|
|
'picture_alt' => fake()->sentence(),
|
|
'picture_title' => fake()->sentence(),
|
|
'picture_thumbnail_alt' => fake()->sentence(),
|
|
'picture_thumbnail_title' => fake()->sentence(),
|
|
'description' => \clean(\fake()->randomHtml(6, 7)),
|
|
'nutriscore' => \collect(NutriscoreEnum::cases())->random(),
|
|
'nutritionnal_values' => $nutritionnal_values,
|
|
'advice' => \clean(\fake()->randomHtml(6, 7)),
|
|
'ingredients' => \clean(\fake()->randomHtml(6, 7)),
|
|
'published' => fake()->boolean(75),
|
|
'range_id' => Range::all()->random()->id,
|
|
];
|
|
}
|
|
}
|