
How to get last record from object collection in laravel
You can get the last record from object collection in laravel using the last() method. The last method helps you to get the last record from an object in laravel.
Answers 1
-
Get last record from object in laravel
--PATH routes\web.phpRoute::get('/get-last-record', function(){ $posts = App\Models\Post::get(); return $posts->last(); });
0You can copy code and paste in your web.php file and run php artisan serve command and click below link to get the output
http://localhost:8000/get-last-record
Output :
{"id":5,"title":"Aliquid sit sit beatae.","description":"Modi veniam est dolores minus voluptatem consectetur ut culpa.
Est minus dolor ullam neque sapiente. Aut magni quidem molestiae exercitationem ut beatae. Adipisci id eligendi mollitia autem.",
"created_at":"2021-08-02T06:08:40.000000Z","updated_at":"2021-08-02T06:08:40.000000Z","category_id":null,"status":"0","user_id":6}
Random Code Snippet Queries: Laravel
- Create record with unique slug in laravel
- How to pass data to route in laravel?
- The use statement with non-compound name 'DB' has no effect
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Laravel create multiple records in Pivot table
- Class 'App\Rules\Hash' not found in Laravel
- Update email with unique validation in laravel
- Ajax GET request in laravel
- How to use more than one query scope in Laravel
- How to get IP address in laravel
- Run artisan command to generate key in laravel
- How to return a column with different name in Laravel
- Extra Filter Query on Relationships in Laravel
- How to increment column value of table in Laravel
- Remove several global scope from query
- How to get the id of last record from collection object in laravel view
- How to create and run user seeder in laravel
- Pass variable from blade to controller Laravel
- How to insert ckeditor data into database in Laravel?
- Order by multiple columns in Laravel
- Ignore Records where a field has NULL value in Laravel
- Laravel 7 login error message not showing
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- How to display validation error in laravel
- Json encode method in laravel