From 085d7411502f9af29194aa3fc26b2722042055c9 Mon Sep 17 00:00:00 2001 From: Norman Huth Date: Sun, 25 Jan 2026 10:42:45 +0100 Subject: [PATCH] feat(recipe): add `variant` attribute to recipes - Add `variant` column to `recipes` table with migration - Update `Recipe` model with `variant` attribute and casting - Extend `ImportRecipeJob` to populate `variant` based on canonical relationship --- app/Jobs/Recipe/ImportRecipeJob.php | 1 + .../Concerns/WithRecipeFilterOptionsTrait.php | 2 ++ app/Models/Recipe.php | 2 ++ ...25_000020_add_variant_to_recipes_table.php | 28 +++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 database/migrations/2026_01_25_000020_add_variant_to_recipes_table.php diff --git a/app/Jobs/Recipe/ImportRecipeJob.php b/app/Jobs/Recipe/ImportRecipeJob.php index 136fb52..86a278d 100644 --- a/app/Jobs/Recipe/ImportRecipeJob.php +++ b/app/Jobs/Recipe/ImportRecipeJob.php @@ -129,6 +129,7 @@ protected function importRecipe(): Recipe 'steps_' . $suffix => $this->transformSteps($this->recipe['steps']), 'nutrition_' . $suffix => $this->recipe['nutrition'], 'yields_' . $suffix => $this->recipe['yields'], + 'variant' => $this->recipe['canonical'] !== '' && $this->recipe['canonical'] !== $this->recipe['id'], 'hellofresh_created_at' => $this->recipe['createdAt'], 'hellofresh_updated_at' => $this->recipe['updatedAt'], ], diff --git a/app/Livewire/Web/Recipes/Concerns/WithRecipeFilterOptionsTrait.php b/app/Livewire/Web/Recipes/Concerns/WithRecipeFilterOptionsTrait.php index 3cddd45..0ba3b9b 100644 --- a/app/Livewire/Web/Recipes/Concerns/WithRecipeFilterOptionsTrait.php +++ b/app/Livewire/Web/Recipes/Concerns/WithRecipeFilterOptionsTrait.php @@ -19,6 +19,8 @@ * @property array $excludedIngredientIds * @property string $ingredientSearch * @property string $excludedIngredientSearch + * @property Collection $ingredientOptions + * @property Collection $excludedIngredientOptions */ trait WithRecipeFilterOptionsTrait { diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index 2071d1c..e8396e5 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -65,6 +65,7 @@ class Recipe extends Model 'nutrition_secondary', 'yields_primary', 'yields_secondary', + 'variant', 'hellofresh_created_at', 'hellofresh_updated_at', ]; @@ -109,6 +110,7 @@ protected function casts(): array 'yields_primary' => 'array', 'yields_secondary' => 'array', 'has_pdf' => 'bool', + 'variant' => 'bool', 'hellofresh_created_at' => 'datetime', 'hellofresh_updated_at' => 'datetime', ]; diff --git a/database/migrations/2026_01_25_000020_add_variant_to_recipes_table.php b/database/migrations/2026_01_25_000020_add_variant_to_recipes_table.php new file mode 100644 index 0000000..a449445 --- /dev/null +++ b/database/migrations/2026_01_25_000020_add_variant_to_recipes_table.php @@ -0,0 +1,28 @@ +boolean('variant')->default(false)->after('has_pdf')->index(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('recipes', static function (Blueprint $table): void { + $table->dropColumn('variant'); + }); + } +};