/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function balances($address_uuid, Guard $auth, Request $request, APIControllerHelper $helper, AccountRepository $account_respository, PaymentAddressRepository $payment_address_repository, LedgerEntryRepository $ledger_entry_repository)
 {
     return DB::transaction(function () use($address_uuid, $auth, $request, $helper, $account_respository, $payment_address_repository, $ledger_entry_repository) {
         $user = $auth->getUser();
         if (!$user) {
             throw new Exception("User not found", 1);
         }
         $payment_address = $helper->requireResourceOwnedByUser($address_uuid, $user, $payment_address_repository);
         $resources = $account_respository->findByAddressAndUserID($payment_address['id'], $user['id'], $this->buildAccountFilter($request, $account_respository));
         // get a (valid) type
         $type = null;
         if (strlen($type_string = $request->input('type'))) {
             try {
                 $type = LedgerEntry::typeStringToInteger($type_string);
             } catch (Exception $e) {
                 return $helper->buildJSONResponse(['message' => 'bad type parameter'], 400);
             }
         }
         // add the balances to each one
         $accounts_with_balances = [];
         foreach ($resources as $account) {
             $account_and_balances = $account->serializeForAPI();
             $balances = $ledger_entry_repository->accountBalancesByAsset($account, $type);
             $account_and_balances['balances'] = $balances;
             $accounts_with_balances[] = $account_and_balances;
         }
         return $helper->buildJSONResponse($accounts_with_balances);
     });
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index($address_uuid, Guard $auth, Request $request, APIControllerHelper $helper, AccountRepository $account_respository, PaymentAddressRepository $payment_address_repository)
 {
     $user = $auth->getUser();
     if (!$user) {
         throw new Exception("User not found", 1);
     }
     $payment_address = $helper->requireResourceOwnedByUser($address_uuid, $user, $payment_address_repository);
     $resources = $account_respository->findByAddressAndUserID($payment_address['id'], $user['id'], $this->buildAccountFilter($request, $account_respository));
     return $helper->transformResourcesForOutput($resources);
 }