piggyBanks()->where('repeats',0)->get(); $accounts = []; /** @var PiggyBank $piggyBank */ foreach ($piggyBanks as $piggyBank) { $piggyBank->savedSoFar = floatval($piggyBank->currentRelevantRep()->currentamount); $piggyBank->percentage = intval($piggyBank->savedSoFar / $piggyBank->targetamount * 100); $piggyBank->leftToSave = $piggyBank->targetamount - $piggyBank->savedSoFar; /* * Fill account information: */ $account = $piggyBank->account; if (!isset($accounts[$account->id])) { $accounts[$account->id] = [ 'name' => $account->name, 'balance' => Steam::balance($account), 'leftForPiggyBanks' => $repository->leftOnAccount($account), 'sumOfSaved' => $piggyBank->savedSoFar, 'sumOfTargets' => floatval($piggyBank->targetamount), 'leftToSave' => $piggyBank->leftToSave ]; } else { $accounts[$account->id]['sumOfSaved'] += $piggyBank->savedSoFar; $accounts[$account->id]['sumOfTargets'] += floatval($piggyBank->targetamount); $accounts[$account->id]['leftToSave'] += $piggyBank->leftToSave; } } return View::make('piggy-banks.index', compact('piggyBanks', 'accounts')); } }