ldc-wenn-dann-mit-respekt/database/factories/ProductFactory.php
2023-05-30 20:26:54 +02:00

63 lines
1.7 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\Products\CertificationsEnum;
use App\Models\Product;
use App\Models\Range;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends Factory<\App\Models\Product>
*/
final 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(): array
{
$label = fake()->unique()->word;
$list = [];
for ($jj = 1; $jj <= 6; $jj++) {
array_push($list, [
"value" => fake()->unique()->words(\rand(2, 8), true)
]);
}
$nutritionnal_values = [];
for ($jj = 1; $jj <= 9; $jj++) {
array_push($nutritionnal_values, [
"label" => fake()->unique()->words(\rand(2, 8), true),
"value" => fake()->unique()->words(2, true)
]);
}
return [
'seo_title' => fake()->word,
'seo_description' => fake()->text(160),
'label' => $label,
'slug' => Str::slug($label),
'description' => fake()->word,
'marinade' => fake()->boolean() ? fake()->word : null,
'picture_alt' => fake()->word,
'picture_title' => fake()->word,
'certifications' => [\collect(CertificationsEnum::cases())->random()],
'nutritionnal_values' => $nutritionnal_values,
'list' => $list,
'status' => fake()->boolean(75),
'range_id' => fake()->randomElement(Range::pluck('id')),
];
}
}