thursday_dan's avatar

Scout pagination features.

Hi guys, need a bit of help with a scout pagination issue.

Ive recently added scout to a page where I was searching multiple tables, implementing multiple paginations one a single page. This works fine.

$actions    = Action::search($request->q)->paginate(50, ['*'], 'ac-page');
$users      = User::search($request->q)->paginate(50, ['*'], 'us-page');

However, when I try with scout I get the following error A non-numeric value encountered.

public function paginate(Builder $builder, $perPage, $page)
   {
       return $this->performSearch($builder, [
           'numericFilters' => $this->filters($builder),
           'hitsPerPage' => $perPage,
           'page' => $page - 1,
       ]);
   }

So I wondered if anyone had any experience of this? (edited)

0 likes
1 reply
thursday_dan's avatar
thursday_dan
OP
Best Answer
Level 1

Found a solution to this. I had to slightly modify what I had before I added scout.

Im sure there is a better approach and a cleaner way of acheiving the same results, so if anyone has any suggestion thatd be great.

$businesses = Business::search($query)->paginate(1, 'bu_page');
$contacts   = Contact::search($query)->paginate(1, 'co_page');
$contracts  = Contract::search($query)->paginate(1, 'cr_page');
$actions    = Action::search($query)->paginate(1, 'ac_page');
$users      = User::search($query)->paginate(1, 'us_page');

$strings = [
   'query' => $query,
   'bu_page' => $businesses->currentPage(),
   'co_page' => $contacts->currentPage(),
   'cr_page' => $contracts->currentPage(),
   'ac_page' => $actions->currentPage(),
   'us_page' => $users->currentPage()
];

$businesses->appends($strings);
$contacts->appends($strings);
$contracts->appends($strings);
$actions->appends($strings);
$users->appends($strings);```

Please or to participate in this conversation.