ldc-le-gaulois-pro/database/factories/ProductFactory.php
2023-01-13 18:06:35 +01:00

72 lines
2.3 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\NutriscoreEnum;
use App\Enums\Products\ProductSpeciesEnum;
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()
{
$packaging = [];
for ($jj = 1; $jj <= 4; $jj++) {
array_push($packaging, [
"value" => $this->faker->unique()->words(rand(2, 8), true)
]);
}
$caliber = [];
for ($jj = 1; $jj <= 4; $jj++) {
array_push($caliber, [
"value" => $this->faker->unique()->words(rand(2, 8), true)
]);
}
$nutritionnal_values = [];
for ($jj = 1; $jj <= 9; $jj++) {
array_push($nutritionnal_values, [
"label" => $this->faker->unique()->words(rand(2, 8), true),
"value" => $this->faker->numberBetween(6, 30)
]);
}
$label = $this->faker->unique()->words(rand(2, 4), true);
return [
'label' => $label,
'slug' => Str::slug($label),
'seo_title' => $this->faker->words(8, true),
'seo_description' => $this->faker->words(25, true),
'species' => collect(ProductSpeciesEnum::toArray())->random(),
'nutriscore' => collect(NutriscoreEnum::toArray())->random(),
'sticker_sm_title' => $this->faker->words(5, true),
'sticker_sm_alt' => $this->faker->words(8, true),
'packaging' => $packaging,
'caliber' => $caliber,
'nutritionnal_values' => $nutritionnal_values,
'ingredients' => $this->faker->unique()->words(rand(15, 25), true),
'advantage' => $this->faker->unique()->words(rand(15, 25), true),
'preparation' => $this->faker->unique()->words(rand(15, 25), true),
'is_frenchpoultry' => $this->faker->boolean(75),
'is_vip' => $this->faker->boolean(25),
'is_egalim' => $this->faker->boolean(25),
'status' => $this->faker->boolean(75)
];
}
}