'How to subtract 2 columns in WHERE condition with Laravel Eloquent

Trjual_h::where('Kd_Pelanggan', '=', $get)
        ->where('Nilai_Faktur', '-', 'Nilai_Bayar', '>=', '0')
        ->select('Nilai_Faktur', 'Tgl_Faktur', 'Lama_Piutang', 'No_Faktur', 'Nilai_Bayar')
        ->get();

I need something like

Select Nilai_Faktur, Tgl_Faktur, Lama_Piutang, No_Faktur, Nilai_Bayar 
where (Kd_Pelanggan = XXX11) AND (Nilai_Faktur - Nilai_Bayar > 0)

But it kept ignoring the two conditions when I run the query, and displaying all available data in my table. Already tried using DB::raw() but it keeps giving me an error.



Solution 1:[1]

simply, you can use query builder

$clients_due_amount = Client::select(DB::raw('SUM(amount - paid) as due_amount'))->first();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shibbir Ahmad