DEV Community

Chidiebere Chukwudi
Chidiebere Chukwudi

Posted on • Updated 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)