You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For real-time chat applications, cursor-based pagination is recommended over offset-based pagination. This prevents duplicate messages when new messages arrive between page loads.
329
+
330
+
```php
331
+
// Get first page
332
+
$messages = Chat::conversation($conversation)
333
+
->setParticipant($participantModel)
334
+
->setCursorPaginationParams([
335
+
'perPage' => 25,
336
+
'sorting' => 'asc',
337
+
])
338
+
->getMessagesWithCursor();
339
+
340
+
// Get next page using cursor from previous response
-`cursor` (optional - from previous response's `next_cursor`)
361
+
362
+
The response includes `next_cursor` and `prev_cursor` for navigation.
363
+
325
364
#### Get user conversations by type
326
365
327
366
```php
@@ -380,6 +419,8 @@ You don't have to specify all the parameters. If you leave the parameters out, d
380
419
`$paginated` above will return `Illuminate\Pagination\LengthAwarePaginator`
381
420
To get the `conversations` simply call `$paginated->items()`
382
421
422
+
> **Tip:** For paginating messages in real-time chat applications, consider using [cursor pagination](#get-messages-with-cursor-pagination) instead. Cursor pagination prevents duplicate messages when new messages arrive between page loads.
0 commit comments