Multiple Column Sorting on Laravel 4 - Kvcodes
X

Congrats, You are Subscribed to Receive Updates.

Multiple Column Sorting on Laravel 4


Multiple Column Sorting on Laravel 4.  In PHP 4 above, we can use direct MySQL  queries to sort based on two columns, But we can’t use the direct MySQL Query here. The following query explains you more,

$kv_query = "SELECT * FROM kvcodes_table ORDER BY  Name DESC, id ASC";

$kv_result = mysql_query($kv_query);

But the above code does not help you to use in laravel, Here we have function to use and  query it. So here in laravel, we have function to use it simply.

orderBy() function simplifies the operations and query writing, The above query will be sorted with the following one,  

Kvcodes_table::orderBy('Name', 'DESC')
              ->orderBy('id', 'ASC')
              ->get();

That’s it, the above snippet will take care of your multiple sorting operations. Likewise you can add many items into it. so sorting will be narrow down with the multiple sortings.

Else, you have alternative choice, you can use “DB::raw() “. Function to use your custom queries as like the Original SQL query. My next post describe the way to do the Raw mySQL query into it.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Congrats, You are Subscribed to Receive Updates.

Advertisement

Category Posts