update pagination livechat

This commit is contained in:
2024-05-17 14:00:24 +07:00
parent 504f152876
commit ba55866203
5 changed files with 37 additions and 18 deletions

View File

@@ -141,8 +141,6 @@ class ChatController extends Controller
'type' => 'file',
]);
}
$data = Message::where('channel_id', $request->channel_id)->get()->toArray();
// Berikan respons yang sesuai ke klien
$channel = Channel::where('id',$request->channel_id)->first();
@@ -162,7 +160,6 @@ class ChatController extends Controller
'message' => 'Message sent successfully',
'data' => [
'header' => $name,
'chat' => $data
]
]);
}
@@ -216,8 +213,14 @@ class ChatController extends Controller
}
// Ini Untul Chat
$data = Message::where('channel_id', $request->channel_id)->get()->toArray();
$perPage = $request->input('per_page', 10); // Default 10 pesan per halaman
$page = $request->input('page', 1); // Default halaman 1
$data = Message::where('channel_id', $request->channel_id)
->where('type', '!=', 'trigger')
->orderBy('created_at', 'desc') // Urutkan berdasarkan created_at secara descending
->paginate($perPage, ['*'], 'page', $page);
// Data Consultation Summary
$consultationSummary = [
'subject' => $livechat->subject,
@@ -230,10 +233,9 @@ class ChatController extends Controller
if ($livechat->health_certificate_start && $livechat->health_certificate_end){
$healthSertificate = True;
}
// Berikan respons yang sesuai ke klien
return response()->json([
'message' => 'Message sent successfully',
'message' => 'Message sent successfully',
'data' => [
'header' => $name,
'avatar' => $avatar,
@@ -244,10 +246,18 @@ class ChatController extends Controller
'end' => $consultationEnd,
'work' => $work,
'address' => $address,
'chat' => $data,
'chat' => $data->items(),
'pagination' => [
'total' => $data->total(),
'per_page' => $data->perPage(),
'current_page' => $data->currentPage(),
'last_page' => $data->lastPage(),
'from' => $data->firstItem(),
'to' => $data->lastItem(),
],
'summary' => $consultationSummary,
'livechat_id' => $livechat->id,
'health_sertificate' => $healthSertificate
'health_sertificate' => $healthSertificate,
]
]);
}