Sync tags _after_ saving recipe

This commit is contained in:
Christopher C. Wells 2021-01-31 13:56:45 -08:00
parent d8ddaf611d
commit fa3c1ee69e
1 changed files with 6 additions and 8 deletions

View File

@ -180,16 +180,9 @@ class RecipeController extends Controller
'servings' => (int) $input['servings'],
]);
// Sync tags.
if ($tags = $request->get('tags')) {
$recipe->syncTags(explode(',', $tags));
}
try {
DB::transaction(function () use ($recipe, $input) {
if (!$recipe->save()) {
return;
}
$recipe->saveOrFail();
// Delete any removed ingredients.
$removed = array_diff($recipe->ingredientAmounts->keys()->all(), $input['ingredients']['original_key']);
@ -243,6 +236,11 @@ class RecipeController extends Controller
return back()->withInput()->withErrors($e->getMessage());
}
// Sync tags.
if ($tags = $request->get('tags')) {
$recipe->syncTags(explode(',', $tags));
}
session()->flash('message', "Recipe {$recipe->name} updated!");
return redirect()->route('recipes.show', $recipe);
}