collection = $collection; // do everything here: $this->getLastActivity(); $this->getMetaBalances(); return $this->collection; } /** * TODO this method refers to a single-use method inside Steam that could be moved here. * @return void */ private function getLastActivity(): void { /** @var AccountRepositoryInterface $accountRepository */ $accountRepository = app(AccountRepositoryInterface::class); $lastActivity = $accountRepository->getLastActivity($this->collection); foreach ($lastActivity as $row) { $this->collection->where('id', $row['account_id'])->first()->last_activity = Carbon::parse($row['date_max'], config('app.timezone')); } } /** * TODO this method refers to a single-use method inside Steam that could be moved here. * @return void */ private function getMetaBalances(): void { try { $array = app('steam')->balancesByAccountsConverted($this->collection, today()); } catch (FireflyException $e) { Log::error(sprintf('Could not load balances: %s', $e->getMessage())); return; } foreach ($array as $accountId => $row) { $this->collection->where('id', $accountId)->first()->balance = $row['balance']; $this->collection->where('id', $accountId)->first()->native_balance = $row['native_balance']; } } }