Skip to content

Commit 0887f0e

Browse files
committed
docs
1 parent 67fc175 commit 0887f0e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

docs/docs/3.0/rest-methods/rest-methods.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,45 @@ Adding error by error in a response instance:
354354
```php
355355
$this->addError('Something went wrong')
356356
```
357+
358+
359+
## Custom Paginator
360+
361+
Sometimes you have a custom paginator collection, and you want to keep the same response format as the `Repository` does.
362+
363+
You can use this static call:
364+
365+
```php
366+
$paginator = User::query()->paginate(5);
367+
368+
$response = Binaryk\LaravelRestify\Controllers\RestResponse::index(
369+
$paginator
370+
);
371+
372+
```
373+
374+
The `$paginator` argument should be an instance of: `Illuminate\Pagination\AbstractPaginator`.
375+
376+
The expected response will contain:
377+
378+
```json
379+
"meta": [
380+
"current_page" :1
381+
"from" :1
382+
"last_page" :1
383+
"path" :"http://localhost"
384+
"per_page" :5
385+
"to" :1
386+
"total" :1
387+
],
388+
"links": [
389+
"first" :"http://localhost?page=1"
390+
"last" :"http://localhost?page=1"
391+
"prev" :null
392+
"next" :null
393+
]
394+
"data": [{...}],
395+
396+
397+
```
398+

0 commit comments

Comments
 (0)