Geoff
Geoff

Reputation: 6649

Laravel using calcuation during eloquent query

I would like to query all products whose net price is less than a certain amount. In my table i am storing only gross price and discount where netprice is the difference between gross price and discount

IN my table i have the following columns

products table

name,
gross_price,
discount_amount

So in my query i would like to get all items whose gross_price - discount_amount is less that a certain amount like 100

SO currently am using eloquent like

Product::where('', '<', 100) //stuck on how to add new net_price in the query

Am stuck on how i can add the calculation to my query. How do i add the calculation without needing to add another field to the table?

Upvotes: 0

Views: 68

Answers (1)

PHP Geek
PHP Geek

Reputation: 4033

Try to use ---

Product::where(\DB::raw('(gross_price - discount_amount)'),'<',100);

Hope it will help you.

Upvotes: 1

Related Questions