J
J
jallvar2020-11-26 12:32:38
Laravel
jallvar, 2020-11-26 12:32:38

How to select last 10 records in laravel without changing sorting?

Hello. I have 100 records in the database.
I need to select the last 10 entries but without changing the sorting
i.e. I set limit(10)->orderBy("id", "desc")
But the records will be displayed like this 100,99,98,97...
I need them to be displayed the other way around from 90,91,92..

How to execute such a query and without iterating in the loop change sorting

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jazzus, 2020-11-26
@jallvar

Another way

Model::orderByDesc('id')
    ->take(10)
    ->get()
    ->sort();

G
Gleb Starkov, 2020-11-26
@colonel

skip or offset

I
Ilya S, 2020-11-26
@Stalinko

Sort records on the PHP side after getting them from the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question