简体   繁体   中英

Laravel eloquent orderBy a date field not returning all values

If I use

$users = User::orderBy('last_modified', 'DESC')->get();

I don't get all the users.

However if I use

$users = User::all();

I get all the users.

The last_modified values in the DB are the same type everybody, a timestamp holding values such as year-month-day 00:00:00

Is that a known Laravel/eloquent issue? Not sure how to debug this... I'm thinking about just getting all the items and then sorting it by the date with PHP...

I return the data with return View::make('dashboard')->with and then use it in the front end with a loop.

All the data is displayed as I want it in the HTML.

Before the loop, the array count is 86. After it, it's still 86 (I did that just to make sure nothing in the loop changed the array).

Then, when console logging the same data used in the loop, data is missing.

var appUsers = {{ json_encode($users); }};
console.log(appUsers);

I also tried console logging at the start of the HTML document and same issue.

When I don't sort by last_modified, no data is missing.

Robert - What does dd(User::orderBy('last_modified', 'DESC')->get()); return on the screen? Is it just an empty collection? I just tried this and I am able to get users sorted by last_modified .

Is it possible you have a typo in your field name in the DB?

Also, do all your users have "00:00:00" at the end of their timestamp? Because users in my system have actual time filled out there.

(I would have asked these questions as comments but don't have enough reputation yet.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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