Prevent exception on empty tags field

This commit is contained in:
Christopher C. Wells 2021-01-24 21:06:12 -08:00
parent 5bc1499e1a
commit 354e73ef67
4 changed files with 10 additions and 8 deletions

View File

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

View File

@ -186,8 +186,9 @@ class RecipeController extends Controller
]); ]);
// Sync tags. // Sync tags.
$tags = explode(',', $request->get('tags')); if ($tags = $request->get('tags')) {
$recipe->syncTags($tags); $recipe->syncTags(explode(',', $tags));
}
try { try {
DB::transaction(function () use ($recipe, $input) { DB::transaction(function () use ($recipe, $input) {

View File

@ -94,10 +94,10 @@
</div> </div>
</div> </div>
<div class="grid grid-rows-3 sm:grid-rows-3 md:grid-rows-2 lg:grid-rows-1 grid-flow-col"> <div class="flex flex-col md:flex-row">
@foreach ($nutrients as $nutrient) @foreach ($nutrients as $nutrient)
<!-- {{ ucfirst($nutrient) }} --> <!-- {{ ucfirst($nutrient) }} -->
<div> <div class="flex-auto">
<x-inputs.label for="{{ $nutrient }}" <x-inputs.label for="{{ $nutrient }}"
:value="ucfirst($nutrient) . ' (g)'"/> :value="ucfirst($nutrient) . ' (g)'"/>

View File

@ -48,10 +48,10 @@
</div> </div>
</div> </div>
<div class="flex flex-auto"> <div class="flex flex-col md:flex-row">
@foreach (\App\Support\Nutrients::$all as $nutrient) @foreach (\App\Support\Nutrients::$all as $nutrient)
<!-- {{ ucfirst($nutrient) }} --> <!-- {{ ucfirst($nutrient) }} -->
<div> <div class="flex-auto">
<x-inputs.label for="{{ $nutrient }}" <x-inputs.label for="{{ $nutrient }}"
:value="ucfirst($nutrient) . ' (g)'"/> :value="ucfirst($nutrient) . ' (g)'"/>