How to show data by ID in laravel?

Created 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.