A
A
Analka2020-02-07 13:00:29
Laravel
Analka, 2020-02-07 13:00:29

How to load data from last id to pen id?

Tell me how to load messages, as in VK, when scrolling up, add previous messages
offset is the number by which we shift the selection, but here it goes from the last id to the first, and I don’t know how to do the shift

$offset = $request->offset * $request->limit;
$messages = DB::table('dialog_messages')
                        ->leftJoin('user_attributes','user_attributes.user_id','=','dialog_messages.user_id')
                        ->select('user_attributes.avatar','user_attributes.fullname','dialog_messages.replay','dialog_messages.created_at','user_attributes.user_id','dialog_messages.id')
                        ->where('dialog_messages.dialog_id','=', $request->dialog_id)
                        ->latest()->offset($offset)->take($request->limit)->get();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Gamov, 2020-02-07
@slowdream

You are not sorting by id, but by date (which does not change the essence, but still).
Replace ->latest()with ->oldest()and it will change the order.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question