/**
* @param ServerRequestInterface $request
* @param array $where
* @return \Illuminate\Database\Eloquent\Collection
* @throws InvalidParameterException
*/
private function getPosts(ServerRequestInterface $request, array $where)
{
$queryParams = $request->getQueryParams();
$actor = $request->getAttribute('actor');
$sort = $this->extractSort($request);
$limit = $this->extractLimit($request);
if (($near = array_get($queryParams, 'page.near')) > 1) {
if (count($where) > 1 || !isset($where['discussion_id']) || $sort) {
throw new InvalidParameterException('You can only use page[near] with ' . 'filter[discussion] and the default sort order');
}
$offset = $this->posts->getIndexForNumber($where['discussion_id'], $near, $actor);
$offset = max(0, $offset - $limit / 2);
} else {
$offset = $this->extractOffset($request);
}
return $this->posts->findWhere($where, $actor, $sort, $limit, $offset);
}