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();
// Sync tags.
$tags = explode(',', $request->get('tags'));
$food->syncTags($tags);
if ($tags = $request->get('tags')) {
$food->syncTags(explode(',', $tags));
}
session()->flash('message', "Food {$food->name} updated!");
return redirect()->route('foods.show', $food);

View File

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

View File

@ -94,10 +94,10 @@
</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)
<!-- {{ ucfirst($nutrient) }} -->
<div>
<div class="flex-auto">
<x-inputs.label for="{{ $nutrient }}"
:value="ucfirst($nutrient) . ' (g)'"/>

View File

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