Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

biniyam20's avatar

Method Illuminate\Database\Eloquent\Collection::paginate does not exist.

Method Illuminate\Database\Eloquent\Collection::paginate does not exist.

On this query paginate(100) causes the error above

        $listings = Auth::user()->listings
                                ->where('availability', 'Y')
                                ->sortBy('title')
                                ->paginate(100);

however on the query below it does not

$listings = Listing::where('availability', 'Y')
                          ->where('user_id', Auth::id())
                          ->where(function ($query) use ($Isbn){
                              $query->where('isbn13', $Isbn)
                                    ->orWhere('isbn', $Isbn);
                            })
                          ->orderBy('title', 'asc')
                          ->paginate(100);

I "dd'd" both listings and observed they are of the same type! I can still share the exact results if someone would like. They are both collections of listings.

Any thoughts on how I can paginate the first query? My initial reaction is maybe there is an issue with using eloquent has many relationships then paginating.

0 likes
4 replies
tykus's avatar
tykus
Best Answer
Level 104

Auth::user()->listings is a Collection

Auth::user()->listings() is a query builder.

The full query should be:

$listings = Auth::user()->listings()
    ->where('availability', 'Y')
    ->orderBy('title')
    ->paginate(100);

Edit note that the sortBy method is a Collection method, you should use orderBy on the query builder.

1 like
biniyam20's avatar

Perfect @tykus thank you so much!

And yes I caught that sortBy is a collection method and I should use orderBy, as I did in the second query.

I would have never thought the relationship model could be used as a method. I need to dig into the documentation more! Thanks again!

tykus's avatar

A relationship used as a property will return the result of the relationship query - a Collection, a Model instance or null.

A relationship called as a method will return a Builder instance which allows you to scope the relationship query further.

1 like
biniyam20's avatar

Thank you @tykus ! I just joined the Laravel community about a month ago so I'm still learning the finer details. I appreciate the help.

1 like

Please or to participate in this conversation.