Fix bug on dashboard with spendings that had no tag
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -63,12 +63,14 @@ class DashboardController extends Controller {
$spendingsByTags = [];
foreach ($spendings as $spending) {
+ if ($spending->tag) {
if (!isset($spendingsByTag[$spending->tag->name])) {
$spendingsByTags[$spending->tag->name] = 0;
}
$spendingsByTags[$spending->tag->name] += $spending->amount;
}
+ }
return view('dashboard', compact(
'year',

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
<div class="row">
<div class="column">
<a href="/spendings/{{ $spending->id }}">{{ $spending->description }}</a>
+ @if ($spending->tag)
<p class="spacing-top-small">{{ $spending->tag->name }} &middot; {{ date('jS', strtotime($spending->date)) }}</p>
+ @else
+ <p class="spacing-top-small">{{ date('jS', strtotime($spending->date)) }}</p>
+ @endif
</div>
<div class="column text-align-right align-middle">
<h3>{{ $currency->symbol }} {{ $spending->amount }}</h3>

Fix bug on dashboard with spendings that had no tag