Reputation: 329
I want to compare two column as condition in Eloquent Laravel. For example: I have 3 columns, qty_1, qty_2, and price. I wanto to get product which price under 1000 if column qty_1 and qty_2 are equal. I have tried these codes but not working:
Product::whereColumn('qty_1','=','qty_2', function($query){
return $query->where('price','<', 1000);
});
How to do that? Thank you.
Upvotes: 2
Views: 2317
Reputation: 34678
Try this :
Product::whereColumn('qty_1','qty_2')
->where('price','<',1000)
->get();
Upvotes: 3