diff --git a/app/Http/Controllers/JournalDateController.php b/app/Http/Controllers/JournalDateController.php new file mode 100644 index 0000000..0b89140 --- /dev/null +++ b/app/Http/Controllers/JournalDateController.php @@ -0,0 +1,21 @@ +route('journal-entries.show'); + } + +} diff --git a/app/Http/Controllers/JournalEntryController.php b/app/Http/Controllers/JournalEntryController.php index f1692fe..7e296fe 100644 --- a/app/Http/Controllers/JournalEntryController.php +++ b/app/Http/Controllers/JournalEntryController.php @@ -8,6 +8,7 @@ namespace App\Http\Controllers; use App\Http\Requests\StoreFromNutrientsJournalEntryRequest; use App\Http\Requests\StoreJournalEntryRequest; use App\Models\Food; +use App\Models\Goal; use App\Models\JournalEntry; use App\Models\Recipe; use App\Support\ArrayFormat; @@ -53,11 +54,20 @@ class JournalEntryController extends Controller } } + // Get all goals as options to change for the date. + $goalOptions = Goal::whereUserId(Auth::user()->id) + ->orderBy('name') + ->get() + ->map(function (Goal $goal) { + return ['value' => $goal->id, 'label' => $goal->name]; + }); + return view('journal-entries.index') ->with('entries', $entries) ->with('sums', $sums) - ->with('goal', $goal) + ->with('currentGoal', $goal) ->with('goalProgress', $goalProgress) + ->with('goalOptions', $goalOptions) ->with('date', $date); } diff --git a/resources/views/journal-entries/index.blade.php b/resources/views/journal-entries/index.blade.php index 8a8d893..10dcc43 100644 --- a/resources/views/journal-entries/index.blade.php +++ b/resources/views/journal-entries/index.blade.php @@ -100,14 +100,25 @@

Goal

- @empty($goal) + @empty($currentGoal)
No goal.
@else - {{ $goal->name }} + href="{{ route('goals.show', $currentGoal) }}"> + {{ $currentGoal->name }} @endempty +
+ @csrf + + +
+ Change Goal +
+
@foreach(['breakfast', 'lunch', 'dinner', 'snacks'] as $meal) diff --git a/routes/auth.php b/routes/auth.php index 7628fdc..3173d0f 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -3,6 +3,7 @@ use App\Http\Controllers\FoodController; use App\Http\Controllers\GoalController; use App\Http\Controllers\IngredientPickerController; +use App\Http\Controllers\JournalDateController; use App\Http\Controllers\JournalEntryController; use App\Http\Controllers\ProfileController; use App\Http\Controllers\RecipeController; @@ -30,6 +31,9 @@ Route::middleware(['auth'])->group(function () { // Ingredient picker. Route::get('/ingredient-picker/search', [IngredientPickerController::class, 'search'])->name('ingredient-picker.search'); + // Journal dates. + Route::post('/journal-dates/update/goal', [JournalDateController::class, 'updateGoal'])->name('journal-dates.update.goal'); + // Journal entries. Route::get('/journal-entries/create/from-nutrients', [JournalEntryController::class, 'createFromNutrients'])->name('journal-entries.create.from-nutrients'); Route::post('/journal-entries/create/from-nutrients', [JournalEntryController::class, 'storeFromNutrients'])->name('journal-entries.store.from-nutrients');