Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1stevengrant/cda92d4148017c1dbad4948e612eb344 to your computer and use it in GitHub Desktop.
Save 1stevengrant/cda92d4148017c1dbad4948e612eb344 to your computer and use it in GitHub Desktop.
pagination object API example
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $posts = Post::paginate(20);

        $data = $posts->items();
        $pagination = [
            'previous_page_url' => $posts->previousPageUrl(),
            'next_page_url' => $posts->nextPageUrl()
        ];
        return [
            "pagination" => $pagination,
            "data" => $data
        ];
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment