Laravel order by ASC DESC


DB::table(‘table_name’)->orderBy(‘column_name’,’DESC_ASC’)->get(); is used for order by condition in laravel.
Where first parameter is column name and second parameter is direction of order ie. DESC or ASC.


Laravel order by ASC clause Example – ASC order

We are going to fetch data with orderBy clause in laravel from the table emp.

DB::table('emp')->orderBy('name', 'asc')->get();

Will Generate query like this.

//Select * from emp order by name ASC ;

Laravel order by DESC clause Example – DESC order

We are going to fetch data with orderBy clause in laravel from the table emp.

DB::table('emp')->orderBy('name', 'desc')->get();

Will Generate query like this.

//Select * from emp order by name DESC;


Advertisements

Add Comment

📖 Read More