getClass(); $model = new $resourceClass; $args = $context['args'] ?? []; $first = isset($args['first']) ? (int) $args['first'] : null; $last = isset($args['last']) ? (int) $args['last'] : null; $after = $args['after'] ?? null; $before = $args['before'] ?? null; $limit = $first ?? $last ?? 10; $offset = 0; if ($after) { $decoded = base64_decode($after, true); $offset = ctype_digit((string) $decoded) ? ((int) $decoded + 1) : 0; } if ($before) { $decoded = base64_decode($before, true); $cursor = ctype_digit((string) $decoded) ? (int) $decoded : 0; $offset = max(0, $cursor - $limit); } $query = $this->linksHandler->handleLinks( $model->newQuery(), $uriVariables, ['operation' => $operation, 'modelClass' => $operation->getClass()] + $context ); $filters = $context['filters'] ?? []; foreach ($filters as $column => $value) { if ($model->getConnection()->getSchemaBuilder()->hasColumn($model->getTable(), $column)) { $query->where($column, $value); } } $total = (clone $query)->count(); if ($offset > $total) { $offset = max(0, $total - $limit); } $items = $query ->offset($offset) ->limit($limit) ->get(); $currentPage = $total > 0 ? (int) floor($offset / $limit) + 1 : 1; return new Paginator( new LengthAwarePaginator( $items, $total, $limit, $currentPage, ['path' => request()->url()] ) ); } }