Respond with a pagination response.

@param \Illuminate\Pagination\Paginator $paginator
@param \Illuminate\Http\Request         $request

@return \Illuminate\Http\JsonResponse
773811
protected function paginator(Paginator $paginator, Request $request)
    {
        foreach ($request->query as $key => $value) {
            if ($key != 'page') {
                $paginator->appends($key, $value);
            }
        }

        $pagination = [
            'pagination' => [
                'total'        => (int) $paginator->total(),
                'count'        => count($paginator->items()),
                'per_page'     => (int) $paginator->perPage(),
                'current_page' => (int) $paginator->currentPage(),
                'total_pages'  => (int) $paginator->lastPage(),
                'links'        => [
                    'next_page'     => $paginator->nextPageUrl(),
                    'previous_page' => $paginator->previousPageUrl(),
                ],
            ],
        ];

        $items = $paginator->getCollection();

        return $this->setMetaData($pagination)->setData(AutoPresenter::decorate($items->values()))->respond();
    }
1308406
public function dispatch(
        PageIndexerRequest $request,
        PageIndexerResponse $response
    ) {
        $actions = $request->getActions();

        foreach ($actions as $action) {
            $frontendHelper = $this->frontendHelperManager->resolveAction($action);
            $frontendHelper->activate();
            $frontendHelper->processRequest($request, $response);
        }
    }
612656
public function dashboard(Request $request, PaginatorInterface $paginator)
    {
        $this->denyAccessUnlessGranted('c975LPayment-dashboard', null);

        //Pagination
        $payments = $paginator->paginate(
            $this->paymentService->getAll(),
            $request->query->getInt('p', 1),
            50
        );

        //Renders the dashboard
        return $this->render('@c975LPayment/pages/dashboard.html.twig', array(
            'payments' => $payments,
        ));
    }
242838
public function serializeCollection(Collection $collection, Request $request, $paginator)
    {
        $transformer = $this->getFractalTransformer($collection->get(0), $request);

        $resource = new Fractal\Resource\Collection($collection, $transformer, $this->getResourceName());
        $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));

        return $this->getFractalManager($request)->createData($resource)->toArray();
    }
1130948
public function call(Request $request, Response $response) : Response {

		return call_user_func($this->callable, $request, $response, $this->slugs);

	}
383804
protected function response($json)
    {
        if ($json instanceof PaginatedResource) {
            $json = json_encode($json);
        }

        return (new HttpFoundationFactory())->createResponse($this->addHeaders(new Response($json)));
    }
79296
public function read(Paginator $paginator = NULL) {
		if ($this->hasNonSaveEntity() === FALSE) {
			$this->rows = array();
		}
		$this->selection = $this->buildSql($paginator);
		return $this;
	}
298106
public function preparePaginationResponse()
    {
        return new Response($this->total, $this->perPage, $this->page, $this->lastPage);
    }
1054969
public function setPaginator(PaginatorInterface $paginator) {
		$this->_paginator = $paginator;
		$this->_pageParam = $paginator->getPageParam();
		
		return $this;
	}
306949
protected function paginate(array $data, Request $request)
    {
        $data = new Collection($data);
        $page = $request->get('page', 1);
        $path = $request->url();

        return new LengthAwarePaginator(
            $data->forPage($page, $this->perPage),
            $data->count(),
            $this->perPage,
            $page,
            compact('path')
        );
    }
654434
public function toResponse($request)
    {
        return tap(response()->json(
            $this->wrap(
                $this->resource->resolve($request),
                array_merge_recursive(
                    $this->paginationInformation($request),
                    $this->resource->with($request),
                    $this->resource->additional
                )
            ),
            $this->calculateStatus()
        ), function ($response) use ($request) {
            $response->original = $this->resource->resource->pluck('resource');

            $this->resource->withResponse($request, $response);
        });
    }
1266054
protected function handleInvalidPage(LengthAwarePaginator $paginator)
    {
        if ($paginator->lastPage() && $paginator->currentPage() > $paginator->lastPage()) {
            $lastPageUrl = Request::fullUrlWithQuery([
                $paginator->getPageName() => $paginator->lastPage(),
            ]);

            Pjax::respond(redirect($lastPageUrl));
        }
    }
1076907
public function paginator()
    {
        $paginator = $this->paginate();

        if (!is_null($this->presenter)) {
            return (new $this->presenter($paginator))->render();
        }

        return $paginator->render();
    }
59742
private function bootPaginator()
    {
        Paginator::currentPathResolver(function () {
            return url();
        });

        Paginator::currentPageResolver(function ($pageName = 'page') {
            return request()->input($pageName);
        });
    }
470970
public function list(Request $request, PaginatorInterface $paginator)
    {
        // Get Query
        $query = $this->getDoctrine()
            ->getRepository($this->getParameter('pd_mailer.mail_template_class'))
            ->createQueryBuilder('m');

        // Get Result
        $pagination = $paginator->paginate(
            $query,
            $request->query->getInt('page', 1),
            $request->query->getInt('limit', $this->getParameter('pd_mailer.list_count'))
        );

        // Set Back URL
        $this->get('session')->set('backUrl', $request->getRequestUri());

        // Render Page
        return $this->render('@PdMailer/list.html.twig', [
            'templates' => $pagination,
            'base_template' => $this->getParameter('pd_mailer.base_template')
        ]);
    }
1158067
public function applyRequestQueryParams(AbstractPaginator $paginator)
	{
		// Pass in any additional query variables
		foreach (
			array_except(
				Request::instance()->query->all(), [
					self::PAGINATION_CURRENT_PAGE,
					self::PAGINATION_PER_PAGE
				]
			) as $key => $value
		) {
			$paginator->addQuery($key, $value);
		}
		// Add our "per page" pagination parameter to the constructed URLs
		$paginator->addQuery(self::PAGINATION_PER_PAGE, $paginator->perPage());
	}
466100
def paginate_response(self, queryset, serializers_kwargs={}):
        
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True, **serializers_kwargs)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(queryset, many=True, **serializers_kwargs)
        return Response(serializer.data)