Level 54
use orderByRaw() instead of the normal orderBy() method.
Then for your specific example, I believe you could do:
->orderByRaw('FIELD(id,5,3,7,1,6,12,8)')
12 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi! I'm making a bit custom orderBy, how can I get rid of second parameter? it always sets desc when I put any other value (false, null, empty string).
p.s. if you wonder what I'm doing - I need to order by whereIn (so need something like order by id(5,3,7,1,6,12,8) and yes, I do need eloquent for eager loading and other awesome stuff it gives.
use orderByRaw() instead of the normal orderBy() method.
Then for your specific example, I believe you could do:
->orderByRaw('FIELD(id,5,3,7,1,6,12,8)')
Please or to participate in this conversation.