1"use strict";(self.webpackChunkfirestore_eloquent=self.webpackChunkfirestore_eloquent||[]).push([[9310],{3909:(e,n,i)=>{i.r(n),i.d(n,{assets:()=>l,contentTitle:()=>r,default:()=>h,frontMatter:()=>s,metadata:()=>d,toc:()=>o});var a=i(5893),t=i(1151);const s={sidebar_position:7},r="Pagination",d={id:"guide/eloquent/pagination",title:"Pagination",description:"Pagination in Firestore Eloquent Library",source:"@site/versioned_docs/version-1.x/guide/eloquent/pagination.mdx",sourceDirName:"guide/eloquent",slug:"/guide/eloquent/pagination",permalink:"/docs/1.x/guide/eloquent/pagination",draft:!1,unlisted:!1,editUrl:"https://github.com/FreddyWhest/firestore-eloquent-docs/tree/main/versioned_docs/version-1.x/guide/eloquent/pagination.mdx",tags:[],version:"1.x",sidebarPosition:7,frontMatter:{sidebar_position:7},sidebar:"tutorialSidebar",previous:{title:"Relationships",permalink:"/docs/1.x/guide/eloquent/relationships"},next:{title:"Counting Documents",permalink:"/docs/1.x/guide/eloquent/counting-data"}},l={},o=[{value:"Pagination in Firestore Eloquent Library",id:"pagination-in-firestore-eloquent-library",level:2},{value:"Paginating Results with <code>paginate()</code>",id:"paginating-results-with-paginate",level:2},{value:"Basic Pagination",id:"basic-pagination",level:3},{value:"Customizing Page Parameter Name",id:"customizing-page-parameter-name",level:3},{value:"Accessing Paginated Data",id:"accessing-paginated-data",level:3},{value:"Displaying Pagination Links",id:"displaying-pagination-links",level:3},{value:"Displaying Pagination Information",id:"displaying-pagination-information",level:3},{value:"Filtered Pagination",id:"filtered-pagination",level:2},{value:"Basic Filtered Pagination",id:"basic-filtered-pagination",level:3},{value:"Customizing Page Parameter Name",id:"customizing-page-parameter-name-1",level:3},{value:"Accessing Paginated Data",id:"accessing-paginated-data-1",level:3},{value:"Displaying Pagination Links",id:"displaying-pagination-links-1",level:3},{value:"Displaying Pagination Information",id:"displaying-pagination-information-1",level:3},{value:"Customizing Pagination Views",id:"customizing-pagination-views",level:3},{value:"Pagination Methods",id:"pagination-methods",level:2},{value:"Pagination Themes",id:"pagination-themes",level:2}];function c(e){const n={code:"code",h1:"h1",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,t.a)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.h1,{id:"pagination",children:"Pagination"}),"\n",(0,a.jsx)(n.h2,{id:"pagination-in-firestore-eloquent-library",children:"Pagination in Firestore Eloquent Library"}),"\n",(0,a.jsx)(n.p,{children:"Pagination is a crucial feature when dealing with large datasets, and the Firestore Eloquent Library in Laravel provides easy-to-use methods for paginating query results. Let's explore how to implement pagination using the library."}),"\n",(0,a.jsxs)(n.h2,{id:"paginating-results-with-paginate",children:["Paginating Results with ",(0,a.jsx)(n.code,{children:"paginate()"})]}),"\n",(0,a.jsxs)(n.p,{children:["The ",(0,a.jsx)(n.strong,{children:(0,a.jsx)(n.code,{children:"paginate()"})})," method allows you to retrieve a specific number of documents per page, making it easier to navigate through large result sets."]}),"\n",(0,a.jsxs)(n.p,{children:["The ",(0,a.jsx)(n.strong,{children:(0,a.jsx)(n.code,{children:"paginate()"})})," method accepts two arguments:"]}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsx)(n.li,{children:"The number of documents to retrieve per page"}),"\n",(0,a.jsx)(n.li,{children:"The name of the page query parameter"}),"\n"]}),"\n",(0,a.jsx)(n.h3,{id:"basic-pagination",children:"Basic Pagination"}),"\n",(0,a.jsxs)(n.p,{children:["Let's paginate the ",(0,a.jsx)(n.code,{children:"users"})," collection by retrieving 10 documents per page:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Paginate all users with 10 users per page\r\n$users = User::paginate(10);\r\n\n"})}),"\n",(0,a.jsxs)(n.p,{children:["This retrieves the first 10 users and provides pagination information. The pagination information is stored in the ",(0,a.jsx)(n.code,{children:"$users"})," variable, and you can access it using the ",(0,a.jsx)(n.code,{children:"links()"})," method or ",(0,a.jsx)(n.code,{children:"pagination()"})," method:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Paginate all users with 10 users per page\r\n$users = User::paginate(10);\r\n\r\n// Get pagination links\r\n$users->links();\r\n\r\n// Get pagination information\r\n$users->pagination();\n"})}),"\n",(0,a.jsx)(n.h3,{id:"customizing-page-parameter-name",children:"Customizing Page Parameter Name"}),"\n",(0,a.jsxs)(n.p,{children:["By default, the page query parameter name is ",(0,a.jsx)(n.code,{children:"page"}),". You can customize this by passing the name of the page query parameter as the second argument to the ",(0,a.jsx)(n.code,{children:"paginate()"})," method:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Paginate all users with 10 users per page\r\n$users = User::paginate(10, 'p');\r\n\r\n// Get pagination links\r\n$users->links();\r\n\r\n// Get pagination information\r\n$users->pagination();\n"})}),"\n",(0,a.jsx)(n.h3,{id:"accessing-paginated-data",children:"Accessing Paginated Data"}),"\n",(0,a.jsx)(n.p,{children:"You can access the paginated data and other useful information:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Accessing paginated data\r\n$data = $users->data(); // Array of user data for the current page\n"})}),"\n",(0,a.jsx)(n.h3,{id:"displaying-pagination-links",children:"Displaying Pagination Links"}),"\n",(0,a.jsxs)(n.p,{children:["You can display the pagination links using the ",(0,a.jsx)(n.code,{children:"links()"})," method:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"{{-- Dis
1playing pagination links --}}\r\n{!! $users->links() !!}\n"})}),"\n",(0,a.jsx)(n.h3,{id:"displaying-pagination-information",children:"Displaying Pagination Information"}),"\n",(0,a.jsxs)(n.p,{children:["You can display the pagination information using the ",(0,a.jsx)(n.code,{children:"pagination()"})," method:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"{{-- Displaying pagination information --}}\r\n$users->pagination()\n"})}),"\n",(0,a.jsx)(n.h2,{id:"filtered-pagination",children:"Filtered Pagination"}),"\n",(0,a.jsx)(n.h3,{id:"basic-filtered-pagination",children:"Basic Filtered Pagination"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Paginate users with age 25, 10 users per page\r\n$filteredUsers = User::where(['age', '=', 25])->paginate(10);\n"})}),"\n",(0,a.jsxs)(n.p,{children:["In this example, the ",(0,a.jsx)(n.code,{children:"where()"})," method is used to filter users with an age of 25, and the ",(0,a.jsx)(n.code,{children:"paginate()"})," method is then applied to paginate the results, showing 10 users per page."]}),"\n",(0,a.jsx)(n.h3,{id:"customizing-page-parameter-name-1",children:"Customizing Page Parameter Name"}),"\n",(0,a.jsx)(n.p,{children:"Similar to regular pagination, you can customize the name of the page query parameter:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Paginate users with age 25, 10 users per page\r\n$filteredUsers = User::where(['age', '=', 25])->paginate(10, 'p');\n"})}),"\n",(0,a.jsx)(n.h3,{id:"accessing-paginated-data-1",children:"Accessing Paginated Data"}),"\n",(0,a.jsx)(n.p,{children:"You can access the paginated data and other useful information:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"// Accessing paginated data\r\n$data = $filteredUsers->data(); // Array of user data for the current page\n"})}),"\n",(0,a.jsx)(n.h3,{id:"displaying-pagination-links-1",children:"Displaying Pagination Links"}),"\n",(0,a.jsxs)(n.p,{children:["You can display the pagination links using the ",(0,a.jsx)(n.code,{children:"links()"})," method:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"{{-- Displaying pagination links --}}\r\n\r\n// default theme by firestore eloquent library\r\n{!! $filteredUsers->links() !!}\r\n\r\n// bootstrap theme\r\n{!! $filteredUsers->links('bootstrap') !!}\r\n\r\n// tailwind theme\r\n{!! $filteredUsers->links('tailwind') !!}\n"})}),"\n",(0,a.jsx)(n.h3,{id:"displaying-pagination-information-1",children:"Displaying Pagination Information"}),"\n",(0,a.jsxs)(n.p,{children:["You can display the pagination information using the ",(0,a.jsx)(n.code,{children:"pagination()"})," method:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:"{{-- Displaying pagination information --}}\r\n$filteredUsers->pagination()\n"})}),"\n",(0,a.jsx)(n.h3,{id:"customizing-pagination-views",children:"Customizing Pagination Views"}),"\n",(0,a.jsxs)(n.p,{children:["Customize the pagination views by using the data provided by the ",(0,a.jsx)(n.code,{children:"pagination()"})," method:"]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-php",children:'$filteredUsers->pagination()\r\n\r\n//Results\r\n/* \r\n[\r\n "total_pages" => 2,\r\n "per_page" => 10,\r\n "current_page" => 1,\r\n "last_page" => 2,\r\n "next_page" => 2,\r\n "prev_page" => null,\r\n "from" => 0,\r\n "to" => 10,\r\n "total" => 20 ,\r\n];\r\n*/\n'})}),"\n",(0,a.jsx)(n.h2,{id:"pagination-methods",children:"Pagination Methods"}),"\n",(0,a.jsxs)(n.p,{children:["The following methods are available on the ",(0,a.jsx)(n.code,{children:"paginate()"})," method:"]}),"\n",(0,a.jsxs)(n.table,{children:[(0,a.jsx)(n.thead,{children:(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.th,{children:"Method"}),(0,a.jsx)(n.th,{children:"Description"})]})}),(0,a.jsxs)(n.tbody,{children:[(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"data()"})}),(0,a.jsx)(n.td,{children:"Returns an array of paginated data."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"pagination()"})}),(0,a.jsx)(n.td,{children:"Returns an object with pagination information."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"count()"})}),(0,a.jsx)(n.td,{children:"Returns the total number of pages."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"currentPage()"})}),(0,a.jsx)(n.td,{children:"Returns the current page number."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"firstItem()"})}),(0,a.jsx)(n.td,{children:"Returns the starting index of the paginated data."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"hasMorePages()"})}),(0,a.jsxs)(n.td,{children:["Returns ",(0,a.jsx)(n.code,{children:"true"})," if there are more pages, ",(0,a.jsx)(n.code,{children:"false"})," otherwise."]})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"totalPages()"})}),(0,a.jsx)(n.td,{children:"Returns the total number of pages."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"lastItem()"})}),(0,a.jsx)(n.td,{children:"Returns the ending index of the paginated data."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"lastPage()"})}),(0,a.jsx)(n.td,{children:"Returns the last page number."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"nextPageUrl()"})}),(0,a.jsx)(n.td,{children:"Returns the URL for the next page."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"previousPageUrl()"})}),(0,a.jsx)(n.td,{children:"Returns the URL for the previous page."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"onFirstPage()"})}),(0,a.jsxs)(n.td,{children:["Returns ",(0,a.jsx)(n.code,{children:"true"})," if on the first page, ",(0,a.jsx)(n.code,{children:"false"})," otherwise."]})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"url($page)"})}),(0,a.jsx)(n.td,{children:"Returns the URL for a specific page."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"total()"})}),(0,a.jsx)(n.td,{children:"Returns the total number of items."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"getPageName()"})}),(0,a.jsx)(n.td,{children:"Returns the name of the page query parameter."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"links($theme = null)"})}),(0,a.jsx)(n.td,{children:"Returns HTML pagination links."})]})]})]}),"\n",(0,a.jsx)(n.h2,{id:"pagination-themes",children:"Pagination Themes"}),"\n",(0,a.jsx)(n.p,{children:"The following pagination themes are available:"}),"\n",(0,a.jsxs)(n.table,{children:[(0,a.jsx)(n.thead,{children:(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.th,{children:"Theme"}),(0,a.jsx)(n.th,{children:"Description"})]})}),(0,a.jsxs)(n.tbody,{children:[(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"default"})}),(0,a.jsx)(n.td,{children:"Default theme by firestore eloquent library."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"bootstrap"})}),(0,a.jsx)(n.td,{children:"Bootstrap theme."})]}),(0,a.jsxs)(n.tr,{children:[(0,a.jsx)(n.td,{children:(0,a.jsx)(n.code,{children:"tailwind"})}),(0,a.jsx)(n.td,{children:"Tailwind theme."})]})]})]})]})}function h(e={}){const{wrapper:n}={...(0,t.a)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(c,{...e})}):c(e)}},1151:(e,n,i)=>{i.d(n,{Z:()=>d,a:()=>r});var a=i(7294);const t={},s=a.createContext(t);function r(e){const n=a.useContext(s);return a.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function d(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:r(e.components),a.createElement(s.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.