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
- Call to a member function pluck() on null
- Redirect to another view from controller in laravel
- How to display 1 day ago in comments in laravel view
- Laravel onclick function not working
- Get 30 days older records from table in laravel
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- How to get id of next record in laravel
- How to check email is valid or not in Laravel
- How to restore deleted records in laravel
- Trying to get property 'title' of non-object
- How to get all route list
- How to get selected categories on edit record with Select2
- Laravel route redirect not working
- How to create pivot table in laravel using migration
- How to add background image to div using Tailwindcss, Vite in Laravel Environment
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist
- How to generate .env file for laravel?
- Ajax GET request in laravel
- How to use bootstrap pagination in laravel 8
- OrderBy on Eloquent relationships method in Laravel
- Insert Comma Separated Values in laravel
- Sample .htaccess file and index.php file under public directory in laravel
- 419 page expired error in Laravel
- How to print form data in laravel
- How to create project_user pivot table in laravel