jaeyson's avatar

Pagination total items is 1000 even though record count is 2000

Hi, I'm using seeder to create 2000 records and using livewire pagination. pk is integer, starting at 1 and ends at 2000 and it is using Meilisearch.

E.g. I have a model (Catalog):

Catalog::paginate(10)->total() // a total of 2,000 records
2000

Catalog::search('')->paginate(10)->total() // 1000 idk why

Catalog::paginate(10)->lastPage() // 200 pages
200

If I have 2000 records with page size of 10, I'd assume the links (buttons) looks something like:

<< [ 1 ] [ 2 ] ... [ 200 ] >>

But in my case it shows

<< [ 1 ] [ 2 ] ... [ 100 ] >>

Which meant it can only render up to 1000 records.

Am I missing something?

0 likes
9 replies
jaeyson's avatar

The post above (Lary AI) didnt work, still stuck at the last item (id of 1000)

Illuminate\Pagination\LengthAwarePaginator {#1631 ▼ // resources/views/livewire/admin-dashboard.blade.php
  #items: Illuminate\Database\Eloquent\Collection {#1613 ▶}
  #perPage: 10
  #currentPage: 6
  #path: "http://localhost/dashboard"
  #query: array:1 [▶]
  #fragment: null
  #pageName: "page"
  +onEachSide: 3
  #options: array:2 [▼
    "path" => "http://localhost/dashboard"
    "pageName" => "page"
  ]
  #total: 1000
  #lastPage: 100
}
Snapey's avatar

you sure your db has 2000 records?

jaeyson's avatar

@Snapey I think i found something: If I change some in search(...) method, all links will be displayed.

so what i did:

if (Str::of($searchTerm)->isNotEmpty()) {
    Catalog::paginate(10);
} else {
    Catalog::search($searchTerm)->paginate(10);
}

I have no clue why an empty string passed inside search method would reduce it into 1000

**I've updated the post above

tykus's avatar

@jaeyson you do realise that search is intended to filter your records, right? Where is $searchTerm coming from anyway?

tykus's avatar

@jaeyson so passing an empty string to search is filtering the result set, you can use the conditional when builder method to check for non-empty search term.

tykus's avatar

@newbie360 good catch; the OP never even thought to mention Scout 🤦‍♂️

Please or to participate in this conversation.