How to get the id of last record from collection object in laravel view
Created at 21-Aug-2021 ,
By samar
How to get the id of last record from collection object in laravel view
In this article, we will see how to solve "How to get the id of last record from collection object in laravel view".
You can get the id of the last record from the collection object using the last() method in your view file. You can call the last() method with no arguments to get the last element in the collection.-
Get id of last record from collection object in laravel view
//routes\web.php Route::get('/get-id-of-last-record', function(){ $posts = App\Models\Post::get(); return view('index')->with(compact('posts')); }); //resources\views\index.blade.php {{ $posts->last()->id }}
-
Get id of last record from collection object in laravel
//routes\web.php Route::get('/get-id-of-last-record', function(){ $posts = App\Models\Post::get(); return $posts->last()->id; });
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
- Cannot end a section without first starting one
- Create project table with model and migration
- How to get session in blade Laravel ?
- Conditional validation in laravel
- Convert input array to comma-separated string in laravel controller
- Laravel 5.4 save data to database
- Session Doesn't Work on Redirect
- Ajax GET request in laravel
- How to Get records between two dates in Laravel
- Method Illuminate\Events\Dispatcher::fire does not exist
- How to check column value of a record is null or not in laravel
- How to return a column with different name in Laravel
- How to upload files to amazon s3 bucket using Laravel
- Create records using relationship in laravel
- Delete all related comments on deleting a post in Laravel
- How to insert dynamic value to additional column in pivot table in laravel
- Get id of last inserted record in laravel
- How to check duplicate entry in laravel
- How to display validation error in laravel
- How to return error message from controller to view in laravel
- Update if exist else insert new record in laravel
- Laravel save object to database
- Laravel 11 sanctum api authentication example code
- Include External CSS and JS file in Laravel
- Get products with number of orders in Laravel