From 0fec1d2edefa4b008485862f16ad2616fa387393 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Tue, 2 Mar 2021 20:11:31 -0800 Subject: [PATCH] Redirect to journal entry date if only one date is used --- app/Http/Controllers/JournalEntryController.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/JournalEntryController.php b/app/Http/Controllers/JournalEntryController.php index e0b34fb..4c4f681 100644 --- a/app/Http/Controllers/JournalEntryController.php +++ b/app/Http/Controllers/JournalEntryController.php @@ -184,7 +184,7 @@ class JournalEntryController extends Controller return back()->withInput()->withErrors("Invalid ingredient type {$ingredient['type']}."); } - // Update summary + // Set entry summary. $unit = $ingredient['unit']; if ($item instanceof Food) { if ($unit === 'serving') { @@ -209,7 +209,14 @@ class JournalEntryController extends Controller $count = count($entries); session()->flash('message', "Added {$count} journal entries!"); - return redirect()->route('journal-entries.index'); + + // Redirect to the date if only one date is used. + $parameters = []; + $unique_dates = array_unique($input['ingredients']['date']); + if (count($unique_dates) === 1) { + $parameters['date'] = reset($unique_dates); + } + return redirect()->route('journal-entries.index', $parameters); } /**