Is episode an integer or a string? How did you define it in your migration? It looks like it is ordering it as a string.
Dec 8, 2015
8
Level 7
How to orderBy data?
Hello, I am having trouble ordering numbers in laravel
Minecraft::where('slug', $slug)->firstOrFail()->episodes()->orderBy('episode', 'desc')->get();;
This is my code, It did well to order the episode from 9 to 1 (desc) but when it reach 10 it start at the part after 1
9, 8, 7, 6, 5, 4, 3, 2, 12, 11, 10, 1
what do i need to get the value from higher to lower?
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
thank you
Level 88
Well ordering a string is completely different from ordering an integer. In this case I would highly recommend you to convert that column to an integer.
You can of course use a raw query and convert the string to an integer: http://stackoverflow.com/questions/11808573/sql-order-string-as-number
1 like
Please or to participate in this conversation.