How to show data by ID in laravel?
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.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
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.
Random Code Snippet Queries: Laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- How to get laravel errors folder in views directory in laravel
- Laravel save object to database
- Redirect from www to non www in laravel using htaccess
- How to increment column value of table in Laravel
- FirstOrCreate() Not Inserting Model
- Laravel append URI in route
- Pass variable from blade to controller Laravel
- How to get path from current URL in Laravel
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- Define variable and use in Laravel controller method
- Insert data with form validation using ajax in laravel
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- How to add a key value pair to existing array in laravel
- Get laravel version
- How to display 1 day ago in comments in laravel view
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- How to add foreign key in laravel using migration
- How to set column as primary key in Laravel model
- How to check if user has created any post or not in laravel
- How to display HTML tags In Laravel blade
- If condition in Laravel 9
- Permission denied error while creating storage link in Laravel
- Convert multidimensional array to single array in Laravel
- Count all and get 10 records after where condition in laravel