Skip to content

Commit

Permalink
fix: keyName column may not be present in pagination cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory Haddow committed Oct 29, 2024
1 parent 6e79095 commit 1386ad7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Pagination/Cursor/CursorParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ public function __construct(private IdParser $idParser, private string $keyName)
*/
public function encode(LaravelCursor $cursor): string
{
$key = $cursor->parameter($this->keyName);

if ($key) {
try {
$key = $cursor->parameter($this->keyName);
$parameters = $this->withoutPrivate($cursor->toArray());
$parameters[$this->keyName] = $this->idParser->encode($key);
$cursor = new LaravelCursor($parameters, $cursor->pointsToNextItems());
} catch (\UnexpectedValueException $ex) {
// Do nothing as the cursor does not contain the key.
}

return $cursor->encode();
Expand Down

0 comments on commit 1386ad7

Please sign in to comment.