Skip to content

Instantly share code, notes, and snippets.

@hootlex
Created June 15, 2016 16:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hootlex/2b0594370e1a5c21dff50ccead84a32e to your computer and use it in GitHub Desktop.
Save hootlex/2b0594370e1a5c21dff50ccead84a32e 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