Merge branch 'duration' into 'develop'

fix: 🐛 update recipe duration type

See merge request ldc-web/projets/nature-and-respect!67
This commit is contained in:
noah.lancien 2025-07-17 15:08:38 +00:00
commit 5195c59687
2 changed files with 43 additions and 1 deletions

View file

@ -98,7 +98,6 @@ class Recipe extends Model implements SeoInterface, SchemaOrgInterface
'picture_thumbnail_alt',
'picture_thumbnail_title',
'ingredients',
'duration',
'teaser',
'steps',
'tips',

View file

@ -0,0 +1,43 @@
<?php
use App\Models\Recipe;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Recipe::query()->get()->map(function (Recipe $recipeModel) {
$i18nDuration = json_decode($recipeModel->duration, true);
$recipeModel->duration = intval($i18nDuration['en'] ?? $i18nDuration['de'] ?? 1);
$recipeModel->saveOrFail();
});
Schema::table('recipes', function (Blueprint $table) {
$table->unsignedSmallInteger('duration')->comment('Recipe duration.')->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('recipes', function (Blueprint $table) {
$table->string('duration')->comment('Temps de réalisation de la recette')->change();
});
$i18nDuration = in_array('duration', (new Recipe())->translatable);
Recipe::query()->get()->map(function (Recipe $recipeModel) use ($i18nDuration) {
$recipeModel->duration = $i18nDuration ? $recipeModel->duration : ['en' => "$recipeModel->duration"];
$recipeModel->saveOrFail();
});
}
};