Skip to content

Firefly III: a personal finances manager

Removed for-loop in favour of "pluck()" aka: RTFM.

James Cole638184cf668a
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php
index 1e08433502..7a5c11c985 100644
--- a/app/Repositories/Bill/BillRepository.php
+++ b/app/Repositories/Bill/BillRepository.php
@@ -7,7 +7,6 @@ use Carbon\Carbon;
use DB;
use FireflyIII\Models\Account;
use FireflyIII\Models\Bill;
-use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -66,13 +65,7 @@ class BillRepository implements BillRepositoryInterface
{
/** @var Collection $set */
$set = Auth::user()->bills()->orderBy('name', 'ASC')->get();
-
- $ids = [];
- /** @var Account $account */
- foreach ($accounts as $account) {
- $ids[] = $account->id;
- }
-
+ $ids = $accounts->pluck('id')->toArray();
$set = $set->filter(
function (Bill $bill) use ($ids) {
// get transaction journals from or to any of the mentioned accounts.
@@ -156,12 +149,8 @@ class BillRepository implements BillRepositoryInterface
$set = DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $bill->amount_min)->where('amount', '<=', $bill->amount_max)->get(
['transaction_journal_id']
);
- $ids = [];
+ $ids = $set->pluck('transaction_journal_id')->toArray();
- /** @var Transaction $entry */
- foreach ($set as $entry) {
- $ids[] = intval($entry->transaction_journal_id);
- }
$journals = new Collection;
if (count($ids) > 0) {
$journals = Auth::user()->transactionjournals()->transactionTypes([TransactionType::WITHDRAWAL])->whereIn('transaction_journals.id', $ids)->get(