简体   繁体   English

laravel查询顺序按不起作用

[英]laravel query orderBy doesn't work

I'm trying to get all my items from item table ordering by product id, desc or asc. 我正在尝试通过商品ID,DESC或ASC从商品表订购中获取所有商品。

Query : 查询:

    public function getAllItems($brandid)
    {
       $data=DB::table('items')->where('brandid',$brandid)
                            ->orderBy('productid' , 'desc')
                            ->get();
        return $data;
    }

Data appears with no order by product id, orderBy is not working. 数据显示没有按产品ID排序的订单,orderBy无法正常工作。 Where is the problem ? 问题出在哪儿 ?

Ok, problem solved, I had 2 functions with the same name, my mistake. 好了,问题解决了,我有两个同名的函数,我的错。 Thank you 谢谢

To check your query statement to confirm the problem with your query builder: 要检查查询语句以确认查询生成器存在的问题,请执行以下操作:

DB::enableQueryLog();
$data=DB::table('items')->where('brandid',$brandid)
                       ->orderBy('productid' , 'desc')
                       ->get();
dd(DB::getQueryLog());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM