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

Answers 2
  • Display data orderby id DESC in laravel

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

    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();
    
    0

    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