ldc-lionor/database/factories/ProductFactory.php
2023-08-28 08:46:47 +00:00

81 lines
3 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\CookingModeEnum;
use App\Enums\NutriscoreEnum;
use App\Models\Product;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Factories\Factory;
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()
{
$name = $this->faker->unique()->words((int)$this->faker->randomFloat(0, 5, 6), true);
$hasConInfo = $this->faker->boolean(70);
$ingredients = [];
for ($i = (int)$this->faker->randomFloat(0, 5, 6); $i > 0; $i--) {
$ingredients[] = \array_merge(Product::ingredient(), [
'label' => $this->faker->word(),
'value' => \sprintf(
'%d%s %s',
(int)$this->faker->randomFloat(0, 1, 56),
'%',
$this->faker->word()
)
]);
}
Product::ingredient();
return [
'name' => $name,
'slug' => Str::slug($name),
'seo_title' => $this->faker->words(7, true),
'seo_description' => $this->faker->words(15, true),
'picture' => new \SplFileInfo(\resource_path(
'../database/factories/assets/products/lionor-product-sample.jpg'
)),
'picture_alt' => $this->faker->unique()->words((int)$this->faker->randomFloat(0, 5, 6), true),
'picture_title' => $this->faker->unique()->words((int)$this->faker->randomFloat(0, 2, 4), true),
'sticker' => new \SplFileInfo(\resource_path(
'../database/factories/assets/products/lionor-product-sticker-sample.jpg'
)),
'sticker_alt' => $this->faker->unique()->words((int)$this->faker->randomFloat(0, 5, 6), true),
'sticker_title' => $this->faker->unique()->words((int)$this->faker->randomFloat(0, 2, 4), true),
'description' => \clean($this->faker->unique()->randomHtml()),
'preparation' => $this->faker->boolean(70) ? \clean($this->faker->unique()->randomHtml()) : null,
'ingredients' => \clean($this->faker->unique()->randomHtml()),
'info_cooking' => $this->faker->boolean(70) ?
$this->faker->unique()->words((int)$this->faker->randomFloat(0, 1, 2), true) : null,
'info_consumption' => $hasConInfo ?
$this->faker->unique()->words((int)$this->faker->randomFloat(0, 1, 2), true) : null,
'cooking_mode' => $hasConInfo ? \collect(CookingModeEnum::toArray())->random()->value :
CookingModeEnum::withoutCooking->value,
'nutriscore' => \collect(NutriscoreEnum::toArray())->random()->value,
'nutritional_values' => $ingredients,
'status' => $this->faker->boolean(75)
];
}
}