Laravel 5.4 Query Builder - where is the condition with two table fields

So, I'm trying to use the query when choosing productswhich is at the Critical level . Thus, if a product is quantitybelow it reorder_point, it will be considered critical .

Here is mine query, which I use:

$products = DB::table('inventory')
            ->where('quantity', '<=', 'reorder_point')
            ->orderBy('quantity', 'asc')
            ->get();

But it is displayed only after quantitythis line is set to 0or less. Therefore, I believe that the value is re_orderpointin the where clause 0.

But everything works when I use this query in phpMyAdmin:

SELECT * from inventory where quantity <= reorder_point

+4
source share
1 answer

Laravel whereColumn . :

$products = DB::table('inventory')
        ->whereColumn('quantity', '<=', 'reorder_point')
        ->orderBy('quantity', 'asc')
        ->get();

. docs here. , .

+3

Source: https://habr.com/ru/post/1684175/


All Articles