I could take the test directly in the view
@if($product->stock <= $product->stock_min)
...
But it's not very clean, I prefer to have the maximum logic outside the view. So anyone has a solution ?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I try to have the products whose stock is smaller or equal than the minimum stock. So I have this :
$products = PRODUCT::with('category')->where('stock', '<=', 'stock_min')->get();
But it doesn't work ! Because only the products with 0 stock is displaying, it doesn't care about the 'stock_min' value. (The stock and stock_min fields are "double" type.)
Hello, you can use whereRaw:
$products = PRODUCT::with('category')->whereRaw('stock <= stock_min')->get();
Please or to participate in this conversation.