B L Praveen
B L Praveen

Reputation: 1990

Get All Latest Records Using Laravel Eloquent

I tried querying the database this way but it returns the error.

latest() not found.

DailyReport::get()->latest()->paginate(10)

I want it to return all the DailyReports with pagination.

Upvotes: 2

Views: 5500

Answers (2)

user633440
user633440

Reputation:

The latest() method is short for orderBy('created_at', 'desc'). You can achieve what you want by:

$latest_daily_reports = DailyReport::latest()->paginate(10);

You can also change the column latest() orders by.

->latest('your_column_name');

Upvotes: 5

Hamid Baseri
Hamid Baseri

Reputation: 31

This is because get().

You should try DailyReport::latest()->paginate(10)

Upvotes: 0

Related Questions