
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
- How to pass query string with pagination in laravel
- How to get count of all records created at yesterday
- Cast Array to an Object in Controller and then pass to view in laravel
- How to get tomorrow and yesterday date in laravel
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- Class 'App\Http\Controllers\User' not found
- Include External CSS and JS file in Laravel
- Laravel form request validation
- Route group with URI prefix using middleware and route name prefixes
- Call to a member function pluck() on null
- Get domain name in laravel
- How to get date from created_at field in laravel
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- How to pass link from controller to view in laravel on ajax call
- How to use or operator in laravel
- How to create controller in laravel
- Retain selected value of select box in Laravel
- Return view from route Laravel
- Target class [HomeController] does not exist
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- How to create laravel project using composer
- Php artisan make model, factory, migration and controller in single command
- How to check data inserted or deleted in pivot after toggle method
- Seed database using SQL file in Laravel
- How to display a specific word from a string in laravel