
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
- Recursive function example code PHP Laravel
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- The use statement with non-compound name 'Auth' has no effect
- Rename Pivot Table in Laravel
- The use statement with non-compound name 'DB' has no effect
- Method Illuminate\Events\Dispatcher::fire does not exist
- Cast Array to an Object in Controller and then pass to view in laravel
- How to get the random value form a specific column in laravel ?
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- How to get only time from created_at in laravel
- Credit card validation in laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- How to run a specific seeder class in laravel
- How to get last month records in Laravel
- File_put_contents(/var/www/html/w3code/storage/framework/sessions/CXwN3EXKxERD6jgy3rADcaAAbAx8FRKih2JK7UO9): Failed to open stream: Permission denied
- How to add active class to menu item in laravel
- Datetime field in Laravel migration
- How to add columns in existing table using migration in laravel
- PhpMyAdmin - Error The mysqli extension is missing
- Link storage folder in laravel 8
- How to check records exist in loaded relationship in Laravel blade view
- Get comma separated email from input array
- Check if Relationship Method Exists in Laravel
- How to pass external link in laravel blade to anchor tag
- Php artisan make model, factory, migration and controller in single command