How to order by character and number in laravel?

Member

by deron , in category: PHP Frameworks , 9 months ago

How to order by character and number in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , 9 months ago

@deron 

To order by character and number in Laravel, you can use the orderByRaw method in your query builder. Here's an example:

1
2
3
$items = DB::table('items')
    ->orderByRaw('LENGTH(name), name')
    ->get();


In this example, we are sorting the items by the length of the name first, and then by the name itself. This will first sort the items by the number of characters in the name, and then alphabetically.


You can adjust the orderByRaw method according to your specific requirements.

Related Threads:

How to get order number of file in dropzone.js?
How to encode a character in laravel?
How to remove url from woocommerce my account order number?
How to count the number of data in laravel?
How to order result by highest in laravel?
How to order by custom time format in laravel?