8000 [Bugfix] Nest page meta by default · volldigital/laravel-json-api@07e6930 · GitHub 65F1
[go: up one dir, main page]

Skip to content

Commit 07e6930

Browse files
committed
[Bugfix] Nest page meta by default
This matches the previous version of this package, that always nested the page meta. By adding this back in, the upgrade path is better. The improvement here is nesting can be turned off if required. Nesting the meta is a better default anyway because it avoids collisions with other meta keys that are being included in the document's top-level meta key.
1 parent ac55c4f commit 07e6930

File tree

2 files changed

+18
-6
lines changed

UPGRADE-0.8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class Adapter extends EloquentAdapter
311311
{
312312
public function __construct(StandardStrategy $paging)
313313
{
314-
$paging->withMetaKey('page')->withUnderscoredMetaKeys();
314+
$paging->withPerPageKey('limit')->withUnderscoredMetaKeys();
315315
parent::__construct(new Post(), $paging);
316316
}
317317
}

src/Pagination/StandardStrategy.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function __construct(FactoryInterface $factory, LinkFactoryInterface $lin
8585
{
8686
$this->factory = $factory;
8787
$this->linkFactory = $linkFactory;
88+
$this->metaKey = QueryParametersParserInterface::PARAM_PAGE;
8889
}
8990

9091
/**
@@ -98,6 +99,17 @@ public function withPageKey($key)
9899
return $this;
99100
}
100101

102+
/**
103+
* @param $key
104+
* @return $this
105+
*/
106+
public function withPerPageKey($key)
107+
{
108+
$this->perPageKey = $key;
109+
110+
return $this;
111+
}
112+
101113
/**
102114
* @param $cols
103115
* @return $this;
@@ -132,15 +144,15 @@ public function withUnderscoredMetaKeys()
132144
/**
133145
* Set the key for the paging meta.
134146
*
135-
* Use this if you need to 'nest' the paging meta in a sub-key of the JSON API
136-
* document's top-level meta object.
147+
* Use this to 'nest' the paging meta in a sub-key of the JSON API document's top-level meta object.
148+
* A string sets the key to use for nesting. Use `null` to indicate no nesting.
137149
*
138-
* @param $key
150+
* @param string|null $key
139151
* @return $this
140152
*/
141153
public function withMetaKey($key)
142154
{
143-
$this->metaKey = $key;
155+
$this->metaKey = $key ?: null;
144156

145157
return $this;
146158
}
@@ -170,7 +182,7 @@ protected function getPageKey()
170182
*/
171183
protected function getPerPage(Collection $collection)
172184
{
173-
return $collection->get($this->getPerPageKey());
185+
return (int) $collection->get($this->getPerPageKey());
174186
}
175187

176188
/**

0 commit comments

Comments
 (0)
0