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

[9.x] Fixes pagination count when Laravel\Scout\Builder contains custom query callback #469

Merged
merged 6 commits into from
Apr 26, 2021

Conversation

crynobone
Copy link
Member

@crynobone crynobone commented Apr 26, 2021

This solved issue #450

Current Behaviour

e.g: GIven users table contains 100 rows with Laravel with 50 male and 50 female.

$users = User::search('Laravel')->paginate();

// $users->total() == 100
$users = User::search('Laravel')->query(function ($builder) {
    return $builder->where('gender', 'male');
})->paginate();

// $users->total() == 100 // which is incorrect.

New Behaviour

If Laravel\Scout\Builder contain custom query callback, we will count the number of rows from eloquent and not use search results coming from Scout engines.

$users = User::search('Laravel')->query(function ($builder) {
    return $builder->where('gender', 'male');
})->paginate();

// $users->total() == 50

Signed-off-by: Mior Muhammad Zaki crynobone@gmail.com

…uery callback.

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@driesvints driesvints changed the title Fixes pagination count when Laravel\Scout\Builder contains custom query callback. [9.x] Fixes pagination count when Laravel\Scout\Builder contains custom query callback Apr 26, 2021
crynobone and others added 4 commits April 26, 2021 23:36
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@taylorotwell taylorotwell merged commit 6753643 into laravel:master Apr 26, 2021
@crynobone crynobone deleted the paginate-on-custom-query branch April 26, 2021 15:54
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

Successfully merging this pull request may close these issues.

3 participants