@php $recipe ??= null; $initialIngredients = old('ingredients', $recipe?->ingredients->map(fn ($i) => [ 'id' => $i->id, 'name' => $i->name, 'quantity' => $i->quantity, 'media' => $i->media->map(fn ($m) => ['id' => $m->id, 'url' => $m->url()])->toArray(), ])->toArray() ?? []); $initialSteps = old('steps', $recipe?->steps->map(fn ($s) => [ 'id' => $s->id, 'name' => $s->name, 'description' => $s->description, 'media' => $s->media->map(fn ($m) => ['id' => $m->id, 'url' => $m->url()])->toArray(), ])->toArray() ?? []); if (empty($initialIngredients)) { $initialIngredients = [['id' => null, 'name' => '', 'quantity' => '', 'media' => []]]; } if (empty($initialSteps)) { $initialSteps = [['id' => null, 'name' => '', 'description' => '', 'media' => []]]; } $initialTags = old('tags', $recipe?->tags->pluck('name')->implode(', ')); @endphp