From 453ad36b149fcdcf17d8255ddf88479f1c72de6f Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Wed, 6 Jul 2022 19:31:15 +0100 Subject: [PATCH] Update cursor pagination chapter for injecting id field --- 2.0/schemas/pagination.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/2.0/schemas/pagination.md b/2.0/schemas/pagination.md index d148e06..d4b79ac 100644 --- a/2.0/schemas/pagination.md +++ b/2.0/schemas/pagination.md @@ -198,11 +198,18 @@ class PostSchema extends Schema */ public function pagination(): CursorPagination { - return CursorPagination::make(); + return CursorPagination::make($this->id()); } } ``` +:::tip +Note that we inject the schema's ID field into the cursor pagination instance. +This is required so the cursor pagination can encode and decode resource ids, if +encoding/decoding is implemented by your resource. +::: + + This means the following request: ```http @@ -249,7 +256,7 @@ For example: ```php public function pagination(): CursorPagination { - return CursorPagination::make() + return CursorPagination::make($this->id()) ->withLimitKey('size') ->withAfterKey('starting-after') ->withBeforeKey('ending-before'); @@ -279,7 +286,7 @@ method. If you prefer your list to be in ascending order, use the ```php public function pagination(): CursorPagination { - return CursorPagination::make() + return CursorPagination::make($this->id()) ->withCursorColumn('published_at') ->withAscending(); }