diff --git a/app/Http/Controllers/JournalEntryController.php b/app/Http/Controllers/JournalEntryController.php index 3fd44cf..713574f 100644 --- a/app/Http/Controllers/JournalEntryController.php +++ b/app/Http/Controllers/JournalEntryController.php @@ -195,13 +195,22 @@ class JournalEntryController extends Controller } /** - * Remove the specified resource from storage. - * - * @param \App\Models\JournalEntry $journalEntry - * @return \Illuminate\Http\Response + * Confirm removal of the specified resource. */ - public function destroy(JournalEntry $journalEntry) + public function delete(JournalEntry $journalEntry): View { - // + return view('journal-entries.delete')->with('entry', $journalEntry); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(JournalEntry $journalEntry): RedirectResponse + { + $journalEntry->delete(); + session()->flash('message', 'Journal entry deleted!'); + return redirect(route('journal-entries.index', [ + 'date' => $journalEntry->date->toDateString() + ])); } } diff --git a/app/Support/Nutrients.php b/app/Support/Nutrients.php index 2689fd1..32c1e69 100644 --- a/app/Support/Nutrients.php +++ b/app/Support/Nutrients.php @@ -30,7 +30,11 @@ class Nutrients return $amount; } - if (empty($fromUnit) || $food->serving_unit === $fromUnit) { + if ( + empty($fromUnit) + || empty($food->serving_unit) + || $food->serving_unit === $fromUnit + ) { $multiplier = 1; } elseif ($fromUnit === 'tsp') { diff --git a/resources/views/foods/index.blade.php b/resources/views/foods/index.blade.php index 3bc61ad..9efca4d 100644 --- a/resources/views/foods/index.blade.php +++ b/resources/views/foods/index.blade.php @@ -12,9 +12,9 @@
@foreach ($foods as $food)
- - + diff --git a/resources/views/journal-entries/delete.blade.php b/resources/views/journal-entries/delete.blade.php new file mode 100644 index 0000000..713ee09 --- /dev/null +++ b/resources/views/journal-entries/delete.blade.php @@ -0,0 +1,40 @@ + + +

+ Delete {{ $entry->summary }}? +

+ + +
+ diff --git a/resources/views/journal-entries/index.blade.php b/resources/views/journal-entries/index.blade.php index 0ea6633..c61513c 100644 --- a/resources/views/journal-entries/index.blade.php +++ b/resources/views/journal-entries/index.blade.php @@ -49,6 +49,14 @@
{{ $entry->summary }}
+
nutrients: @foreach($nutrients as $nutrient) diff --git a/routes/web.php b/routes/web.php index 8496999..654d870 100644 --- a/routes/web.php +++ b/routes/web.php @@ -30,5 +30,8 @@ Route::get('/foods/{food}/delete', [FoodController::class, 'delete']) ->name('foods.delete'); Route::resource('recipes', RecipeController::class)->middleware(['auth']); Route::resource('journal-entries', JournalEntryController::class)->middleware(['auth']); +Route::get('/journal-entries/{journalEntry}/delete', [JournalEntryController::class, 'delete']) + ->middleware(['auth']) + ->name('journal-entries.delete'); require __DIR__.'/auth.php';