Hi, I'm having a little issue sorting a custom query: $comments = Comment::where('page_name', '1-html')->orderBy('id', 'desc')->get(); foreach($comments as $comment) { echo $page->id . " "; }
The result is: 1 2 3 4 5 6 7 8 Which is odd, since it should be the other way around. Do you have any ideas?
Hi!
We need a little more information to help you out.
In your code example you echo $page
instead of $comment
; Might this be a typo?
Could you also provide a pastebin/gist of your code. This makes it somewhat easier to see what you are doing exactly.
Looking forward to your reply, we're here to help.
Hi, thanks for the very quick reply!
Here is the gist for better overview:
https://gist.github.com/cbacon93/06c38db98108d50d528e95037c757472
Hi!
We're currently looking at this. Please hold tight as we're investigating/reproducing your problem.
Hmm, we've tried your exact implementation with the code you provided but this does not give the same result. Our testing environment orders in the correct way. e.g.:
3 2 1
- Have you tried using
DESC
instead ofdesc
. Might be case sensitivity. - How does you DB dump look?
- Just out of curiosity, what result does ordering by
ASC
yield?
Without trying to shift the blame to you, it looks like it has something to do with your environment/installation. Eloquent sorting methods are standard functionality and the Comments plugin does not alter any of Eloquent's default behaviour.
Thanks for looking into this for me. DESC
instead of desc
gives me the same result, ASC
also gives me the result provided above. It's very strange but doing a direct query with the comment table seems to work. This is my working query:
$query = Db::table('rebel59_comments_comments')
->where('page_name', $data['page_id'])
->where('parent_id', null)
->orderBy('created_at', 'desc')
->limit(30)
->offset(($data['page_number']-1)*30)->get();
The old version with Comment::
still does not seem to work correctly for me.
1-7 of 7