PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 16, 2022

[FIXED] How to use orderBy with Laravel 6 LazyCollection?

 November 16, 2022     laravel, laravel-6     No comments   

Issue

It's been a few days since the Laravel released its latest version 6. I am trying to implement Laravel LazyCollection instead of the normal Collection class.

Following line works-

Drug::where('deactive',0)->orderBy('code')->get();

And when I use

Drug::cursor()->where('deactive',0)->orderBy('code')->get();

I get an error Method Illuminate\Support\LazyCollection::orderBy does not exist.

Can anyone help me how to use OrderBy with LazyCollection?

UPDATE

After getting the answer here is the correct syntax of above query

Drug::cursor()->where('deactive',0)->sortBy('code');

Solution

Offcourse, orderBy method is Query builder method. You can use sortBy as defined in the docs



Answered By - guttume
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,214,369

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing