I have recently started working on Laravel and now I'm having issue related joins. Good human please look into this you might help me.
I have two table one is cable_users and other is cable_transactions connected with primary foreign key relation. cable_users.id is in relation with cable_transactions.cableUser
all the transaction related to that cable user are get stored in cable_transactions table but now I want only the latest record from the cable_transactions table.
$customers = DB::table('cable_users')
->leftJoin('cable_transactions', 'cable_users.id', '=', 'cable_transactions.cableUser')
->where('cable_users.status', 'active')
->select('cable_users.id', 'cable_users.name', 'cable_users.mobile', 'cable_users.address', 'cable_users.packageName', 'cable_users.status','cable_transactions.packageAmount','cable_transactions.advanceRemaining', 'cable_transactions.advanceAmount', 'cable_transactions.pendingAmount', 'cable_transactions.updated_at')
->orderBy('cable_users.id','DESC')
->orderBy('cable_transactions.updated_at','ASC')
->get()->toArray();
from above code I'm getting all the data from cable_transactions table