ldc-nature-and-respect/database/factories/RecipeFactory.php

59 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2023-03-16 09:47:16 +01:00
<?php
namespace Database\Factories;
use App\Enums\Recipes\DifficultyEnum;
use App\Models\Range;
use App\Models\Recipe;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends Factory<\App\Models\Recipe>
*/
final class RecipeFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Recipe::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition(): array
{
$name = fake()->unique()->word;
2023-03-23 09:08:28 +01:00
2023-05-10 15:02:09 +02:00
$ingredients = [];
2023-03-23 09:08:28 +01:00
for ($jj = 1; $jj <= 9; $jj++) {
2023-05-10 15:02:09 +02:00
array_push($ingredients, [
2023-04-25 13:42:16 +00:00
"value" => fake()->unique()->words(\rand(2, 8), true)
2023-03-23 09:08:28 +01:00
]);
}
2023-03-16 09:47:16 +01:00
return [
'seo_title' => fake()->word,
2023-05-09 15:21:00 +02:00
'seo_description' => fake()->text(160),
2023-03-16 09:47:16 +01:00
'name' => $name,
'slug' => Str::slug($name),
2023-03-23 09:08:28 +01:00
'picture_alt' => fake()->word,
'picture_title' => fake()->word,
'picture_thumbnail_alt' => fake()->word,
'picture_thumbnail_title' => fake()->word,
'ingredients' => $ingredients,
2023-05-09 15:21:00 +02:00
'teaser' => fake()->text(160),
2023-03-16 09:47:16 +01:00
'steps' => fake()->text,
'difficulty' => \collect(DifficultyEnum::cases())->random(),
'duration' => fake()->numberBetween(0, 60),
2023-03-23 09:08:28 +01:00
'tips' => fake()->text,
2023-03-16 09:47:16 +01:00
'range_id' => fake()->randomElement(Range::pluck('id')),
'status' => fake()->boolean(75),
];
}
}