A
A
Analka2020-02-10 12:05:05
Laravel
Analka, 2020-02-10 12:05:05

How to display Laravel pagination?

How to display pagination with such a post?

$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)
->orderBy('dialog_messages.id','DESC')->paginate(15)->reverse()->values();

if I remove it,

->reverse()->values()
it outputs

current_page: 1
data: [,…]
0: {avatar: "uploads/users/avatars/1-2020-02-05-223757.jpg", fullname: "Максим Дроздов", replay: "111111",…}
1: {avatar: "uploads/users/avatars/1-2020-02-05-223757.jpg", fullname: "Максим Дроздов",…}
first_page_url: "http://bet.litesites.ru/profile/dialogs/messages?page=1"
from: 1
last_page: 3
last_page_url: "http://bet.litesites.ru/profile/dialogs/messages?page=3"
next_page_url: "http://bet.litesites.ru/profile/dialogs/messages?page=2"
path: "http://bet.litesites.ru/profile/dialogs/messages"
per_page: 15
prev_page_url: null
to: 15
total: 44

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Analka, 2020-02-10
@Analka

did so

$data = $messages->reverse()->values();
return response()->json([
   'messages' => $data,
   'page' => $messages->currentPage(),
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question