How to show data by ID in laravel?

Updated at 04-Aug-2021, By samar

How to show data by ID in laravel?

In this article, we will see how to solve "How to show data by ID in laravel?".

You can display data in view file using by id in ASC and DESC order in laravel
  • Display data orderby id DESC in laravel

    $posts = Post::orderBy('id', 'DESC')->get();
    

    You can display data in DESC order (3, 2, 1) largest to smallest in laravel view using the orderby() method. The post with id 3 will be on top and after that 2 and 1 will be shown.

  • Display data orderby id ASC in laravel

    $posts = Post::orderBy('id', 'ASC')->get();
    

    You can display data in ASC order (1, 2, 3) smallest to largest in laravel view using the orderby() method. The post with id 1 will be on top and after that 2 and 3 will be shown.

Back to code snippet queries related laravel