Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

esmaill23's avatar

eloquent query that sum of two column greater than a number

i want to build an eloquent query sum of two column greater than a number like this

$query = Transaction::query();
$query = $query->where('plan_price - final_price','>=',5);

how ?

0 likes
2 replies
Tray2's avatar
Tray2
Best Answer
Level 73
Transaction::whereRaw('plan_price - final_price >= 5');

Should work.

Jacobs's avatar

I think you'll have to use the \DB::raw(), as query builder doesn't support such statements at the moment.

$query = Transaction::query()->where(\DB::raw('(plan_price - final_price) >= 5'));

Please or to participate in this conversation.