Allow all tags to be removed

This commit is contained in:
Christopher C. Wells 2021-03-13 14:00:09 -08:00
parent be9c45a414
commit 8db02e302b
2 changed files with 10 additions and 2 deletions

View File

@ -104,9 +104,13 @@ class FoodController extends Controller
$food->fill($attributes)->save();
// Sync tags.
if ($tags = $request->get('tags')) {
$tags = $request->get('tags');
if (!empty($tags)) {
$food->syncTags(explode(',', $tags));
}
elseif ($food->tags->isNotEmpty()) {
$food->detachTags($food->tags);
}
session()->flash('message', "Food {$food->name} updated!");
return redirect()->route('foods.show', $food);

View File

@ -262,9 +262,13 @@ class RecipeController extends Controller
}
// Sync tags.
if ($tags = $request->get('tags')) {
$tags = $request->get('tags');
if (!empty($tags)) {
$recipe->syncTags(explode(',', $tags));
}
elseif ($recipe->tags->isNotEmpty()) {
$recipe->detachTags($recipe->tags);
}
// Handle recipe image.
if (!empty($input['image'])) {