diff --git a/app/Http/Controllers/JournalEntryController.php b/app/Http/Controllers/JournalEntryController.php index d300131..1f17872 100644 --- a/app/Http/Controllers/JournalEntryController.php +++ b/app/Http/Controllers/JournalEntryController.php @@ -3,18 +3,28 @@ namespace App\Http\Controllers; use App\Models\JournalEntry; +use Illuminate\Contracts\View\View; use Illuminate\Http\Request; +use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Auth; class JournalEntryController extends Controller { /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\View\View */ - public function index() + public function index(Request $request): View { - // + $date = $request->date ?? Carbon::now()->toDateString(); + return view('journal.index') + ->with('entries', JournalEntry::where([ + 'user_id' => Auth::user()->id, + 'date' => $date, + ])->get()) + ->with('date', Carbon::createFromFormat('Y-m-d', $date)) + ->with('nutrients', ['calories', 'fat', 'cholesterol', 'carbohydrates', 'sodium', 'protein']); } /** diff --git a/app/Models/JournalEntry.php b/app/Models/JournalEntry.php index 3f02694..cf2fcb4 100644 --- a/app/Models/JournalEntry.php +++ b/app/Models/JournalEntry.php @@ -54,7 +54,7 @@ class JournalEntry extends Model /** * @inheritdoc */ - protected $with = ['user', 'foods', 'recipes']; + protected $with = ['user', 'foods:id,name', 'recipes:id,name']; /** * Get the User this entry belongs to. diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index 2a7d531..f003a5b 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -47,11 +47,6 @@ class Recipe extends JournalableModel 'servings' => 'int', ]; - /** - * @inheritdoc - */ - protected $with = ['steps', 'foodAmounts']; - /** * Nutrient total calculation methods. */ diff --git a/resources/views/journal/index.blade.php b/resources/views/journal/index.blade.php new file mode 100644 index 0000000..2beec47 --- /dev/null +++ b/resources/views/journal/index.blade.php @@ -0,0 +1,58 @@ + + +

+ {{ __(":name's Journal", ['name' => Auth::user()->name]) }} +

+
+ +
+
+ @if(session()->has('message')) +
+ {{ session()->get('message') }} +
+ @endif +
+
+
+ +
+ {{ $date->format('D, j M Y') }} +
+ +
+
+
+

Totals

+ @foreach($nutrients as $nutrient) + {{ round($entries->sum($nutrient), 2) }}g + {{ $nutrient }}@if(!$loop->last), @endif + @endforeach +
+ @foreach(['breakfast', 'lunch', 'dinner', 'snacks'] as $meal) +
+

+ {{ Str::ucfirst($meal) }} +

+
+ @foreach($nutrients as $nutrient) + {{ round($entries->where('meal', $meal)->sum($nutrient), 2) }}g + {{ $nutrient }}@if(!$loop->last), @endif + @endforeach +
+ @forelse($entries->where('meal', $meal) as $entry) +
+ {{ $entry->summary }} + {{ $entry->calories }} +
+ @empty + No entries. + @endforelse +
+ @endforeach +
+
+
+
+
+
diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index ab63fff..c392a76 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -17,6 +17,32 @@ + + +