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
- Best Practices for Error Handling in Production Server Code (example code)
- How to validate form input data in laravel
- Laravel 11 step by step instructions to upload file in storage directory and display in blade file
- How to add columns in existing table using migration in laravel
- How to restore multiple records after soft-deletes in Laravel
- Get posts belongs to a specific user in Laravel
- Send id with route Laravel
- How to get records in random order in laravel
- Get ids in array from users table
- Composer create project laravel/laravel example app
- Seed database using SQL file in Laravel
- Symlink(): No such file or directory
- Post table seeder laravel 10
- Check if Relationship Method Exists in Laravel
- Update existing pivot table data in laravel
- Rename Pivot Table in Laravel
- How to use more than one query scope in Laravel
- How to get date from created_at field in laravel
- Sample configuration files to create laravel project with docker using wsl (window subsystem linux)
- Laravel hasmany select not working
- Get duplicate records in laravel
- How to decrypt laravel password
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- Method Illuminate\Events\Dispatcher::fire does not exist
- Laravel delete all rows older than 30 days