How to get last record from object collection in laravel
How to get last record from object collection in laravel
We’ll attempt to use programming in this lesson to solve the "How to get last record from object collection in laravel" puzzle.
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.-
Get last record from object in laravel
--PATH routes\web.phpRoute::get('/get-last-record', function(){ $posts = App\Models\Post::get(); return $posts->last(); });
You 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}
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
- Array to string conversion laravel blade
- How to display serial number in Laravel?
- How to remove package from laravel
- How to add columns in existing table using migration in laravel
- How to get date from created_at field in laravel
- How to add active class to menu item in laravel
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- Display option of select as selected with blade directive Laravel
- Delete all related comments on deleting a post in Laravel
- How to insert value to additional columns in pivot table in laravel
- Get laravel version
- How to create project_user pivot table in laravel
- Check if Relationship Method Exists in Laravel
- Split an Eloquent Collection by half in Laravel
- Pass value from controller to model in laravel
- How to get count of all records created at yesterday
- The POST method is not supported for this route. Supported methods: PUT.
- Call to undefined relationship [user] on model [App\Models\Post]
- Laravel migration add foreign key to existing table
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- Include External CSS and JS file in Laravel
- How to create new user without form submission in laravel
- Setup laravel project with docker
- First and last item of the array using foreach iteration in laravel blade
- If condition in foreach loop in laravel