如何将 orderBy 与 Laravel 6 LazyCollection 一起使用?
How to use orderBy with Laravel 6 LazyCollection?
Laravel 发布最新版本 6 已经有几天了。我正在尝试实现 Laravel LazyCollection 而不是普通的 Collection class。
以下行有效-
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
中定义的 docs
我觉得你可以做到。
Drug::where('deactive',0)->orderBy('code')->cursor();
Laravel 发布最新版本 6 已经有几天了。我正在尝试实现 Laravel LazyCollection 而不是普通的 Collection class。
以下行有效-
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
中定义的 docs
我觉得你可以做到。
Drug::where('deactive',0)->orderBy('code')->cursor();