Fix query for calculating most expensive tag
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -23,8 +23,7 @@ class DashboardController extends Controller {
$mostExpensiveTag = DB::select('
SELECT
- tags.name AS name,
- SUM(spendings.amount) AS amount
+ tags.name AS name
FROM
tags
LEFT OUTER JOIN
@@ -33,10 +32,12 @@ class DashboardController extends Controller {
tags.user_id = ?
GROUP BY
tags.id
+ HAVING
+ SUM(spendings.amount) > 0
ORDER BY
SUM(spendings.amount) DESC
LIMIT 1;
- ', [$user->id])[0];
+ ', [$user->id]);
$mostExpensiveWeekday = DB::select('
SELECT

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
<div class="row__column">
<div class="box">
<div class="box__section">
- <h2>{{ $mostExpensiveTag->amount ? $mostExpensiveTag->name : '-' }}</h2>
+ <h2>{{ count($mostExpensiveTag) ? $mostExpensiveTag[0]->name : '-' }}</h2>
<div class="mt-1">Most expensive tag</div>
</div>
</div>

Fix query for calculating most expensive tag