@rodrigo.pedra thank you thank you so much for your response.
i tried your code just editing like this, in my controller.
$records = FeePayment::query()
->with(['feeStructure'])
->selectRaw('student_id, feeStructure, SUM(paid_amt + disc_amt - fine_amt) as paid')->where('student_id',74)
->groupBy([ 'student_id', 'fee_main_cat_id'])
->get()
->groupBy('student_id');
Everthing worked fine. i added disc_amount with that, because i have a column in my payment table. and i need a where condition for specifically mention the student so i added that also.
but i have a small problem, if student_id: 5 didnt pay any fee means it should return all the terms fees from feeStrucutre table?? and if a student paid only term1 fee, then the remaining terms fee and its amount should be displayed. so that i will have a link and i will click and pay that in the same payment table.
this is what the output when student:5 doesnt pay any fee means,
Term1 Balance 6000
Term2 Balance 8000
Term3 Balance 10000
Actually this shows the whole, term and fee from feestrucutre table because this student didnt pay any fee. so i have a link by click the amt and it will redirect to payment page.
if the student paid only term1 partially that is , term1 fee is 6000, but he paid only 4000 means the output should be,
Term1 Balance 2000
Term2 Balance 8000
Term3 Balance 10000
How this comes is for term1 he paid 4000 so its balance is shown and remaining term2 and term3 he not paid a single amount, so it shown fully.
as per your query everything works fine, but it shows only when student pays the fee. because the query projects from FeePayment Table.
can you guide me to achieve my output. thank you.
i think i didnt confuse you.