Stop displaying recent earnings/spendings on dashboard
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -8,7 +8,7 @@ use Auth;
use DB;
class DashboardController extends Controller {
- public function index() {
+ public function __invoke() {
$user = Auth::user();
$spendingsToday = $user
@@ -52,18 +52,6 @@ class DashboardController extends Controller {
LIMIT 1;
', [$user->id]);
- $recentEarnings = $user
- ->earnings()
- ->orderBy('happened_on', 'DESC')
- ->limit(3)
- ->get();
-
- $recentSpendings = $user
- ->spendings()
- ->orderBy('happened_on', 'DESC')
- ->limit(3)
- ->get();
-
return view('dashboard', [
'currency' => $user->currency,
@@ -72,8 +60,8 @@ class DashboardController extends Controller {
'mostExpensiveTag' => $mostExpensiveTag,
'mostExpensiveWeekday' => $mostExpensiveWeekday,
- 'recentEarnings' => $recentEarnings,
- 'recentSpendings' => $recentSpendings
+ 'earningsCount' => $user->earnings->count(),
+ 'spendingsCount' => $user->spendings->count()
]);
}
}

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
</div>
<div class="row gutter spacing-bottom-large">
<div class="column">
- <div class="color-dark spacing-bottom-large">Recent Earnings</div>
<div class="box">
- @if (count($recentEarnings))
- <ul class="box__section">
- @foreach ($recentEarnings as $earning)
- <li>
- <div class="row">
- <div class="column">
- <div class="color-dark">{{ $earning->description }}</div>
- <div style="margin-top: 10px;">{{ intval((time() - strtotime($earning->happened_on)) / 86400) }} day(s) ago</div>
- </div>
- <div class="column text-align-right align-middle color-green">{{ $currency->symbol }} {{ number_format($earning->amount / 100, 2) }}</h3></div>
- </div>
- </li>
- @endforeach
- </ul>
- @else
- <div class="box__section">You don't have any earnings</div>
- @endif
- <div class="box__section">
- <a href="/earnings">Show More</a>
+ <div class="box__section text-center" style="padding: 15px;">
+ <a href="/earnings">Earnings ({{ $earningsCount }}) <i class="fa fa-arrow-right"></i></a>
</div>
</div>
</div>
<div class="column">
- <div class="color-dark spacing-bottom-large">Recent Spendings</div>
<div class="box">
- @if (count($recentSpendings))
- <ul class="box__section">
- @foreach ($recentSpendings as $spending)
- <li>
- <div class="row">
- <div class="column">
- <div class="color-dark">{{ $spending->description }}</div>
- <div style="margin-top: 10px;">{{ intval((time() - strtotime($spending->happened_on)) / 86400) }} day(s) ago</div>
- </div>
- <div class="column text-align-right align-middle color-red">{{ $currency->symbol }} {{ number_format($spending->amount / 100, 2) }}</h3></div>
- </div>
- </li>
- @endforeach
- </ul>
- @else
- <div class="box__section">You don't have any spendings</div>
- @endif
- <div class="box__section">
- <a href="/spendings">Show More</a>
+ <div class="box__section text-center" style="padding: 15px;">
+ <a href="/spendings">Spendings ({{ $spendingsCount }}) <i class="fa fa-arrow-right"></i></a>
</div>
</div>
</div>

MODIFY
routes/web.php
routes/web.php
@@ -9,7 +9,7 @@ Route::get('/register', 'RegisterController@index')->name('register');
Route::post('/register', 'RegisterController@store');
Route::group(['middleware' => ['auth']], function () {
- Route::get('/dashboard', 'DashboardController@index')->name('dashboard');
+ Route::get('/dashboard', 'DashboardController')->name('dashboard');
Route::get('/earnings/create', 'EarningsController@create')->name('earnings.create');
Route::post('/earnings', 'EarningsController@store');

Stop displaying recent earnings/spendings on dashboard