Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination on laravel 7x not working #228

Open
NguyenHiep opened this issue Oct 15, 2020 · 3 comments
Open

Pagination on laravel 7x not working #228

NguyenHiep opened this issue Oct 15, 2020 · 3 comments

Comments

@NguyenHiep
Copy link

NguyenHiep commented Oct 15, 2020

I'm trying #75 for pagination.
My code

$number_per_page = 10;
            $records = Book::complexSearch(array(
                'body' => array(
                    'query' => array(
                        'match' => array(
                            'title' => $request->search
                        )
                    ),
                    'from' => ($page-1) * $number_per_page,
                    'size' => $number_per_page
                )
            ))->paginate($number_per_page);

image
I try to debug and i see variable $total not type int, it's is type array ['value' => 10, 'relation' => 'eq']

@NguyenHiep NguyenHiep changed the title Pagination on laravel7x not working Pagination on laravel 7x not working Oct 16, 2020
@Abdullah-Hejazi
Copy link

The problem is from the ElasticquentPaginator class

you need to change line 25 to this:

$this->lastPage = (int) ceil((int)$total / (int)$perPage);

Note: don't change the vendor directly, either fork this repo and make the changes to it, then use it on your application.
or make a pull request to this repo

@NguyenHiep
Copy link
Author

Thank you so much! @Abdullah-Hejazi

@64j
Copy link

64j commented Sep 21, 2023

Need to make changes to class \Elasticquent\ElasticquentResultCollection to method totalHits.
The method returns an array and must be a number.

array:2 [ // vendor/elasticquent/elasticquent/src/ElasticquentResultCollection.php:66
  "value" => 43558
  "relation" => "eq"
]

I suggest making changes

    /**
     * Total Hits
     *
     * @return int
     */
    public function totalHits()
    {
        return $this->hits['total']['value'] ?? $this->hits['total'];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants