I want to build a query that order data by certain field length. I need to rewrite this query to laravel's Eloquent ORM.
SELECT * FROM table ORDER BY CHAR_LENGTH(field)
It seems that orderByRaw
is what you're looking for. Here's an example:
User::orderByRaw('CHAR_LENGTH(name)')->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With