Calculate a user's most expensive weekday and display it on dashboard
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -38,6 +38,20 @@ class DashboardController extends Controller {
LIMIT 1;
', [$user->id])[0];
+ $mostExpensiveWeekday = DB::select('
+ SELECT
+ WEEKDAY(spendings.happened_on) AS weekday
+ FROM
+ spendings
+ WHERE
+ spendings.user_id = ?
+ GROUP BY
+ WEEKDAY(spendings.happened_on)
+ ORDER BY
+ SUM(spendings.amount) DESC
+ LIMIT 1;
+ ', [$user->id]);
+
$recentEarnings = $user
->earnings()
->orderBy('happened_on', 'DESC')
@@ -56,6 +70,7 @@ class DashboardController extends Controller {
'spendingsToday' => $spendingsToday,
'spendingsMonth' => $spendingsMonth,
'mostExpensiveTag' => $mostExpensiveTag,
+ 'mostExpensiveWeekday' => $mostExpensiveWeekday,
'recentEarnings' => $recentEarnings,
'recentSpendings' => $recentSpendings

ADD
resources/lang/en/weekdays.php
+<?php
+
+return [
+ 0 => 'Monday',
+ 1 => 'Tuesday',
+ 2 => 'Wednesday',
+ 3 => 'Thursday',
+ 4 => 'Friday',
+ 5 => 'Saturday',
+ 6 => 'Sunday'
+];

ADD
resources/lang/nl/weekdays.php
+<?php
+
+return [
+ 0 => 'Maandag',
+ 1 => 'Dinsdag',
+ 2 => 'Woensdag',
+ 3 => 'Donderdag',
+ 4 => 'Vrijdag',
+ 5 => 'Zaterdag',
+ 6 => 'Zondag'
+];

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
</div>
</div>
</div>
+ <div class="row__column">
+ <div class="box">
+ <div class="box__section">
+ <h2>{{ count($mostExpensiveWeekday) ? __('weekdays.' . $mostExpensiveWeekday[0]->weekday) : '-' }}</h2>
+ <div class="mt-1">Most expensive weekday</div>
+ </div>
+ </div>
+ </div>
</div>
<div class="row gutter spacing-bottom-large">
<div class="column">

Calculate a user's most expensive weekday and display it on dashboard