I have Bank table and transaction table. The relationship is one-to-many, so a bank may have many transactions. Transaction table has the bank foreign key(bank_id). and each transaction has a column 'type' which is either credit or debit. I want to show each bank balance based on its transactions.
Here are my questions:
I'm not sure what you are trying to do. You'd select a bank like
$bank = Bank::find(2);
and you could do something like
$bank->transactions->sum('amount');