aarondfrancis / fast-paginate

A fast implementation of offset/limit pagination for Laravel.
MIT License
1.21k stars 56 forks source link

Not working with Scout #24

Closed Jaspur closed 2 years ago

Jaspur commented 2 years ago

Method Laravel\Scout\Builder::fastPaginate does not exist.

Schermafbeelding 2022-08-01 om 15 08 03
aarondfrancis commented 2 years ago

Hmm can you give me some more details? Maybe your model setup and what you're calling to generate this error? Thanks!

Jaspur commented 2 years ago

HI @aarondfrancis,

I think I found out what the issue is.

Your package need ::query() to be added to the calls for fastPaginate(). But when I do with Scout, I get this: Call to undefined method Illuminate\Database\Eloquent\Builder::search()

if (request()->has('search')) {
    return new UserCollection(
        User::search(request()->search)
            // ->query() // not working with Scout
            // ->fastPaginate() // does not work with scout, probably because of missing "query()"
            ->paginate() // this works, but I prefer fastPaginate of course ;-)
    );
}
return new UserCollection(
    User::query()->fastPaginate()
);

Probably Scout doesn't work when using ::query() and fastPaginate() doesn't work without it?

aarondfrancis commented 2 years ago

Yeah I only add the macro to the Eloquent builder and Relation class, and since Scout is using its own builder the method isn't there. I could probably add it, or at least let it fall through to the regular paginate so you don't get errors. Let me try some stuff!

aarondfrancis commented 2 years ago

Added support for Scout, cutting a new release now! All it does is defer to the underlying implementation, but it no longer errors out.

Jaspur commented 2 years ago

Whoo, great! Thanks