87 lines
3.1 KiB
PHP
87 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\Advices\AdviceDifficultyEnum;
|
|
use App\Enums\Advices\AdviceTypeEnum;
|
|
use App\Models\Advice;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
class AdviceFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Advice::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function definition()
|
|
{
|
|
$title = $this->faker->unique()->words(rand(2, 4), true);
|
|
$type = $this->faker->numberBetween(1, count(collect(AdviceTypeEnum::toArray())) - 1);
|
|
|
|
$cooking_time = null;
|
|
$preparation_time = null;
|
|
$video_title = null;
|
|
$video_id = null;
|
|
$guest_nb = null;
|
|
$difficulty = null;
|
|
|
|
if ($type == AdviceTypeEnum::recipes()->value) {
|
|
$cooking_time = $this->faker->numberBetween(0, 10);
|
|
$preparation_time = $this->faker->numberBetween(0, 10);
|
|
if ($this->faker->boolean(50)) {
|
|
$video_title = $this->faker->words(8, true);
|
|
$video_id = '7rpgfetac0U';
|
|
}
|
|
$guest_nb = rand(1, 10);
|
|
/** @var \App\Enums\Advices\AdviceDifficultyEnum */
|
|
$difficulty = collect(AdviceDifficultyEnum::toArray())->random();
|
|
} elseif ($type == AdviceTypeEnum::tips()->value) {
|
|
$video_title = $this->faker->words(8, true);
|
|
$video_id = '7rpgfetac0U';
|
|
$guest_nb = $this->faker->boolean(50) ? rand(1, 10) : null;
|
|
}
|
|
$ingredients = [];
|
|
|
|
if (!\is_null($guest_nb)) {
|
|
for ($jj = 1; $jj <= 15; $jj++) {
|
|
array_push($ingredients, [
|
|
'value' => $this->faker->numberBetween(6, 300),
|
|
'label' => $this->faker->unique()->words(rand(2, 8), true),
|
|
]);
|
|
}
|
|
}
|
|
|
|
return [
|
|
'title' => $title,
|
|
'slug' => Str::slug($title),
|
|
'seo_title' => $this->faker->words(8, true),
|
|
'seo_description' => $this->faker->words(25, true),
|
|
'type' => $type,
|
|
'picture_title' => $this->faker->words(5, true),
|
|
'picture_alt' => $this->faker->words(8, true),
|
|
'sticker_title' => $this->faker->words(5, true),
|
|
'sticker_alt' => $this->faker->words(8, true),
|
|
'sticker_sm_title' => $this->faker->words(5, true),
|
|
'sticker_sm_alt' => $this->faker->words(8, true),
|
|
'preparation' => $this->faker->words(25, true),
|
|
'advice' => $this->faker->boolean(75) ? $this->faker->words(25, true) : null,
|
|
'ingredients' => $ingredients,
|
|
'guests_nb' => $guest_nb,
|
|
'youtube_title' => $video_title,
|
|
'youtube_video_id' => $video_id,
|
|
'cooking_time' => $cooking_time,
|
|
'preparation_time' => $preparation_time,
|
|
'difficulty' => $difficulty,
|
|
'status' => $this->faker->boolean(75)
|
|
];
|
|
}
|
|
}
|