From 721c5baa2c01a7a8e3bb622cf1113a09357d8691 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 15 May 2021 19:54:47 -0700 Subject: [PATCH] Add days to Goal index view --- app/Models/Goal.php | 13 +++++-------- resources/views/goals/index.blade.php | 22 +++++++++++----------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/Models/Goal.php b/app/Models/Goal.php index 1d52576..8f00123 100644 --- a/app/Models/Goal.php +++ b/app/Models/Goal.php @@ -86,19 +86,16 @@ final class Goal extends Model /** * Get the days for the goals as strings in array keyed by dow. */ - public function getDaysFormattedAttribute(): array { - $days = []; + public function getDaysFormattedAttribute(): Collection { if (empty($this->days)) { - return $days; + return new Collection([]); } - - self::days()->each(function ($day) use (&$days) { + return self::days()->filter(function ($day) { if (($this->days & $day['value']) != 0) { - $days[$day['dow']] = $day['label']; + return true; } + return false; }); - - return $days; } /** diff --git a/resources/views/goals/index.blade.php b/resources/views/goals/index.blade.php index 943e471..1bd4d48 100644 --- a/resources/views/goals/index.blade.php +++ b/resources/views/goals/index.blade.php @@ -13,25 +13,25 @@ Name Days of Week - Goals -   + Total Calories + Operations @foreach($goals as $goal) - {{ $goal->name }} - {{ $goal->days }} - Calories: {{ $goal->calories }}
- Carbohydrates: {{ $goal->carbohydrates }}
- Cholesterol: {{ $goal->cholesterol }}
- Fat: {{ $goal->fat }}
- Protein: {{ $goal->Protein }}
- Sodium: {{ $goal->sodium }}
+ + {{ $goal->name }} + + + {{ $goal->days_formatted->pluck('label')->join(', ') }} + + {{ number_format($goal->calories) }} -
+
Edit