Search code examples
phplaravellaravel-3

Laravel 3 access all transactions of one customer


Customers have many Accounts, and Accounts have many Transactions.

I want to get all of the transactions from one customer..?

$customer = Auth::user();
$statement = $customers->accounts()->transactions()->where('customer_no', '=',     $customer->customer_no)->get(); //get all transactions

I know this doesn't work but this is the closest I can get..


Solution

  • $customer = Auth::user();
    $account_ids = $customers->accounts()->lists('id');
    $statement = Transaction::where_in('account_id', $account_ids)->where('customer_no', '=', $customer->customer_no)->get(); // Get all transactions
    

    You probably do not need the 'customer_no' part b/c