Display recent earnings on dashboard
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -23,6 +23,12 @@ class DashboardController extends Controller {
->whereRaw('MONTH(happened_on) = ?', [date('m')])
->sum('amount');
+ $recentEarnings = session('space')
+ ->earnings()
+ ->orderBy('created_at', 'DESC')
+ ->limit(3)
+ ->get();
+
$recentSpendings = session('space')
->spendings()
->orderBy('created_at', 'DESC')
@@ -57,7 +63,9 @@ class DashboardController extends Controller {
'totalEarnings' => $totalEarnings,
'totalSpendings' => $totalSpendings,
+ 'recentEarnings' => $recentEarnings,
'recentSpendings' => $recentSpendings,
+
'mostExpensiveTags' => $mostExpensiveTags,
'earningsCount' => session('space')->earnings->count(),

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
@section('body')
<div class="wrapper my-3">
<h2>{{ __('general.dashboard') }}</h2>
- <p class="mt-1">{{ __('calendar.months.' . $month) }} {{ date('Y') }}</p>
- <div class="row row--gutter row--responsive mt-3 mb-4">
+ <div class="row row--gutter row--responsive my-3">
<div class="row__column">
- <div class="card card--green">
- <h2 style="font-size: 20px;">{!! $currency !!} {{ number_format($totalEarnings / 100, 2) }}</h2>
- <div class="mt-1" style="color: #A7AEBB;">{{ __('general.total_earned') }}</div>
- </div>
- </div>
+ <div class="box">
+ <div class="box__section box__section--header">{{ __('general.recent') }} {{ __('general.earnings') }}</div>
+ @if (count($recentEarnings))
+ @foreach ($recentEarnings as $earning)
+ <div class="box__section row row--seperate">
<div class="row__column">
- <div class="card card--red">
- <h2 style="font-size: 20px;">{!! $currency !!} {{ number_format($totalSpendings / 100, 2) }}</h2>
- <div class="mt-1" style="color: #A7AEBB;">{{ __('general.total_spent') }}</div>
+ <div class="color-dark">{{ $earning->description }}</div>
+ <div class="mt-1" style="font-size: 14px;">{{ $earning->formatted_happened_on }}</div>
</div>
+ <div class="row__column row__column--compact row__column--middle color-dark">{!! $currency !!} {{ $earning->formatted_amount }}</div>
</div>
- <div class="row__column">
- <!-- OFFSET -->
+ @endforeach
+ @else
+ <div class="box__section">You don't have any earnings</div>
+ @endif
</div>
</div>
- <div class="row row--gutter row--responsive mb-4">
<div class="row__column">
<div class="box">
<div class="box__section box__section--header">{{ __('general.recent') }} {{ __('general.spendings') }}</div>
@endif
</div>
</div>
+ </div>
+ <p>{{ __('calendar.months.' . $month) }} {{ date('Y') }}</p>
+ <div class="row row--gutter row--responsive my-3">
<div class="row__column">
- <div class="box">
+ <div class="card card--green">
+ <h2 style="font-size: 20px;">{!! $currency !!} {{ number_format($totalEarnings / 100, 2) }}</h2>
+ <div class="mt-1" style="color: #A7AEBB;">{{ __('general.total_earned') }}</div>
+ </div>
+ </div>
+ <div class="row__column">
+ <div class="card card--red">
+ <h2 style="font-size: 20px;">{!! $currency !!} {{ number_format($totalSpendings / 100, 2) }}</h2>
+ <div class="mt-1" style="color: #A7AEBB;">{{ __('general.total_spent') }}</div>
+ </div>
+ </div>
+ <div class="row__column">
+ <!-- OFFSET -->
+ </div>
+ </div>
+ <div class="box mb-3">
<div class="box__section box__section--header">Most Expensive {{ __('general.tags') }}</div>
@if (count($mostExpensiveTags))
@foreach ($mostExpensiveTags as $index => $tag)
<div class="box__section">Not enough data</div>
@endif
</div>
- </div>
- </div>
- <div class="row row--gutter row--responsive spacing-bottom-large">
+ <div class="row row--gutter row--responsive">
<div class="row__column">
<div class="box">
<div class="box__section text-center" style="padding: 15px;">

Display recent earnings on dashboard