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

kendrick's avatar

Method Illuminate\Support\Collection::paginate does not exist

How can I turn my $monday Collection into a query to paginate it?

$doctor = Auth::user()->meeting()->get(); 
$monday = optional($doctor->map->meeting->flatten()->where('start', '=', '12:00:00'))->paginate(2); 

$monday = optional($doctor->map->meeting->flatten()->where('start', '=', '12:00:00'))->take(2); // works

Currently I get a paginate does not exist, as we can only invoke paginate on a Query, not on a Collection.

Method Illuminate\Support\Collection::paginate does not exist
0 likes
13 replies
Tray2's avatar

You should use paginate when you retreive the records from the database.

$doctor = Auth::user()->meeting()->paginate(2);
3 likes
kendrick's avatar

@TRAY2 - Thank you. But what happens to my $monday logic, as I want to paginate the result of $monday.

Currently I get Undefined property: Illuminate\Pagination\LengthAwarePaginator::$map, if I paginate $doctor.

Vilfago's avatar

You can simulate the paginate with take and skip

1 like
kendrick's avatar

@VILFAGO - This one works:

$monday = optional($doctor->map->meeting->flatten()->where('start', '=', '12:00:00'))->take(2); 

But what if there are more than 2 Meetings?

Tray2's avatar

You just add the where to the query.

Auth::user()->meeting()->where('start', '12:00:00')->paginate(2);

Then you don't need that part. Add anny additional wheres to the query.

kendrick's avatar

@TRAY2 - This won't work. Then I will get:

Property [meeting] does not exist on this collection instance.
munazzil's avatar

You can use in the index function as like below as you have to pass the $doctor and $monday in compact funtion,

return view('user.view',compact('doctor','monday'));

and your index.blade.php use as like below end of the table,

     <div> {{ $monday->Links() }}   </div>
ftiersch's avatar

@MUNAZZIL - Man, are you even READING the questions? Your answer has nothing to do with it...

@splendidkeen What does your "meeting" method do? Did you write your own collection logic there?

munazzil's avatar

Then it is suggest that that is not a collection can you dd($doctor) and check and also can change it to an array,

$doctor = Auth::user()->meeting()->get()->toArray()->paginate(2);
YeZawHein's avatar

@splendidkeen I think when you use get() ,you already have a collection.Try it

$doctor = Auth::user()->meeting()->latest(); 

Please or to participate in this conversation.