Shouldn't have removed totalSpendings variable from DashboardController..
MODIFY
app/Http/Controllers/DashboardController.php
app/Http/Controllers/DashboardController.php
@@ -13,11 +13,14 @@ use DB;
class DashboardController extends Controller {
public function __invoke() {
$space_id = session('space')->id;
+ $currentYear = date('Y');
+ $currentMonth = date('m');
- $balance = session('space')->monthlyBalance(2018, 11);
- $recurrings = session('space')->monthlyRecurrings(2018, 11);
+ $balance = session('space')->monthlyBalance($currentYear, $currentMonth);
+ $recurrings = session('space')->monthlyRecurrings($currentYear, $currentMonth);
$leftToSpend = $balance - $recurrings;
+ $totalSpent = session('space')->spendings()->whereRaw('YEAR(happened_on) = ? AND MONTH(happened_on) = ?', [$currentYear, $currentMonth])->sum('amount');
$mostExpensiveTags = DB::select('
SELECT
tags.name AS name,
@@ -45,6 +48,7 @@ class DashboardController extends Controller {
'recurrings' => $recurrings,
'leftToSpend' => $leftToSpend,
+ 'totalSpent' => $totalSpent,
'mostExpensiveTags' => $mostExpensiveTags
]);
}

MODIFY
resources/views/dashboard.blade.php
resources/views/dashboard.blade.php
<script>
@foreach ($mostExpensiveTags as $index => $tag)
var data = {
- series: [{{ $tag->amount }}, {{ $totalSpendings - $tag->amount }}]
+ series: [{{ $tag->amount }}, {{ $totalSpent - $tag->amount }}]
};
new Chartist.Pie('.ct-chart-{{ $index }}', data, {

Shouldn't have removed totalSpendings variable from DashboardController..