more eager loading

This commit is contained in:
Denis Duliçi
2020-06-06 22:57:29 +03:00
parent 657c86a29c
commit a16406ea1e
10 changed files with 11 additions and 11 deletions

View File

@@ -11,7 +11,7 @@ class AccountBalance extends Widget
public function show()
{
$accounts = Account::enabled()->take(5)->get();
$accounts = Account::with(['income_transactions', 'expense_transactions'])->enabled()->take(5)->get();
return $this->view('widgets.account_balance', [
'accounts' => $accounts,

View File

@@ -22,7 +22,7 @@ class TotalExpenses extends Widget
$current += $transaction->getAmountConvertedToDefault();
});
$this->applyFilters(Bill::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($bill) use (&$open, &$overdue) {
$this->applyFilters(Bill::with('transactions')->accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($bill) use (&$open, &$overdue) {
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($bill);
$open += $open_tmp;

View File

@@ -22,7 +22,7 @@ class TotalIncome extends Widget
$current += $transaction->getAmountConvertedToDefault();
});
$this->applyFilters(Invoice::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($invoice) use (&$open, &$overdue) {
$this->applyFilters(Invoice::with('transactions')->accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($invoice) use (&$open, &$overdue) {
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($invoice);
$open += $open_tmp;

View File

@@ -30,14 +30,14 @@ class TotalProfit extends Widget
}
});
$this->applyFilters(Invoice::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($invoice) use (&$open_invoice, &$overdue_invoice) {
$this->applyFilters(Invoice::with('transactions')->accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($invoice) use (&$open_invoice, &$overdue_invoice) {
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($invoice);
$open_invoice += $open_tmp;
$overdue_invoice += $overdue_tmp;
});
$this->applyFilters(Bill::accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($bill) use (&$open_bill, &$overdue_bill) {
$this->applyFilters(Bill::with('transactions')->accrued()->notPaid(), ['date_field' => 'created_at'])->each(function ($bill) use (&$open_bill, &$overdue_bill) {
list($open_tmp, $overdue_tmp) = $this->calculateDocumentTotals($bill);
$open_bill += $open_tmp;