Laravel orderBy, groupBy and limit Example

In this artical we will see laravel orderBy, groupBy, and limit example, in this laravel orderBy, groupBy and limit example we will see different types of laravel 8 query example.

The orderBy method allows you to sort the results of the query by a given column. The first argument accepted by the orderBy method should be the column you wish to sort by, while the second argument determines the direction of the sort and may be either asc or desc.


Laravel Example :

​$users = DB::table('users')
         ->orderBy('name', 'desc')

SQL Query:

select * from `users` order by `name` desc;

Output :

All users name will be sort by descending order.


The groupBy and having methods may be used to group the query results. The having method's signature is similar to that of the where method.

$users = DB::table('users')
         ->having('account_id', '>', 100)



limit method is used to limit the number of results returned from the query.

$users = DB::table('users')


You might also like :



Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.