DEV Community

Chidiebere Chukwudi
Chidiebere Chukwudi

Posted on • Edited on

Laravel: How to get last N entries from DB

I just added an answer to this question on stackoverflow.

Maybe I should write a little note on this ?!

Imagine a situation where you want to get the latest record of data from the request header that was just inserted into the database:

$noOfFilesUploaded = count( $request->pic );// e.g 4
$model = new Model
$model->latest()->take($noOfFilesUploaded); 

This way your take() helper function gets the number of array data that was…

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay