laravel - 如何在 Laravel 6 LazyCollection 中使用 orderBy?
问题描述
Laravel 发布其最新版本 6 已经有几天了。我正在尝试实现 Laravel LazyCollection 而不是普通的 Collection 类。
以下线路工作 -
Drug::where('deactive',0)->orderBy('code')->get();
当我使用
Drug::cursor()->where('deactive',0)->orderBy('code')->get();
我收到一个错误Method Illuminate\Support\LazyCollection::orderBy does not exist.
谁能帮助我如何将 OrderBy 与 LazyCollection 一起使用?
更新
在这里得到答案后是上述查询的正确语法
Drug::cursor()->where('deactive',0)->sortBy('code');
解决方案
当然,orderBy
方法是查询生成器方法。您可以按照文档sortBy
中的定义使用
推荐阅读
- sql-server - SSDT 不会在未解析的引用上引发编译错误
- paypal - 如何在 PayPal 沙盒中测试重复/自动付款配置文件的失败、跳过付款?
- python - 使用 shapely、geopandas 和索引在 python 中连接网格的质心
- javascript - 如果所选选项为空,如何防止提交?
- javascript - RxJS 管道过滤到 2+ 个分支
- arrays - Mongoose 返回一个空数组
- android - 如何处理android布局中的不同分辨率?
- node.js - Electron 主进程 - 无法在 Windows 上获取用户输入
- java - Java:在 finalize() 中抛出异常的影响
- pdf - 为什么 pandoc 不能正确地将纯文本文件转换为 PDF?