Add days to Goal index view

This commit is contained in:
Christopher C. Wells 2021-05-15 19:54:47 -07:00 committed by Christopher Charbonneau Wells
parent 77b06c62b1
commit 721c5baa2c
2 changed files with 16 additions and 19 deletions

View File

@ -86,19 +86,16 @@ final class Goal extends Model
/** /**
* Get the days for the goals as strings in array keyed by dow. * Get the days for the goals as strings in array keyed by dow.
*/ */
public function getDaysFormattedAttribute(): array { public function getDaysFormattedAttribute(): Collection {
$days = [];
if (empty($this->days)) { if (empty($this->days)) {
return $days; return new Collection([]);
} }
return self::days()->filter(function ($day) {
self::days()->each(function ($day) use (&$days) {
if (($this->days & $day['value']) != 0) { if (($this->days & $day['value']) != 0) {
$days[$day['dow']] = $day['label']; return true;
} }
return false;
}); });
return $days;
} }
/** /**

View File

@ -13,25 +13,25 @@
<tr class="bg-gray-200 text-gray-600 uppercase text-sm leading-normal"> <tr class="bg-gray-200 text-gray-600 uppercase text-sm leading-normal">
<th class="py-3 px-6 text-left">Name</th> <th class="py-3 px-6 text-left">Name</th>
<th class="py-3 px-6 text-left">Days of Week</th> <th class="py-3 px-6 text-left">Days of Week</th>
<th class="py-3 px-6 text-left">Goals</th> <th class="py-3 px-6 text-left">Total Calories</th>
<th class="py-3 px-6 text-left">&nbsp;</th> <th class="py-3 px-6 text-left">Operations</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($goals as $goal) @foreach($goals as $goal)
<tr class="border-b border-gray-200"> <tr class="border-b border-gray-200">
<td class="py-3 px-6">{{ $goal->name }}</td>
<td class="py-3 px-6">{{ $goal->days }}</td>
<td class="py-3 px-6"> <td class="py-3 px-6">
Calories: {{ $goal->calories }}<br /> <a class="text-gray-500 hover:text-gray-700 hover:border-gray-300"
Carbohydrates: {{ $goal->carbohydrates }}<br /> href="{{ route('goals.show', $goal) }}">
Cholesterol: {{ $goal->cholesterol }}<br /> {{ $goal->name }}
Fat: {{ $goal->fat }}<br /> </a>
Protein: {{ $goal->Protein }}<br /> </td>
Sodium: {{ $goal->sodium }}<br /> <td class="py-3 px-6">{{ $goal->days_formatted->pluck('label')->join(', ') }}</td>
<td class="py-3 px-6">
{{ number_format($goal->calories) }}
</td> </td>
<td class="py-3 px-6"> <td class="py-3 px-6">
<div class="flex space-x-2 justify-end"> <div class="flex space-x-2 justify-start">
<x-button-link.gray href="{{ route('goals.edit', $goal) }}"> <x-button-link.gray href="{{ route('goals.edit', $goal) }}">
Edit Edit
</x-button-link.gray> </x-button-link.gray>