I am trying to paginate Model result, but I am getting "Method paginate does not exist.". Here is my code:
$user_dispatches = Dispatch::all()->where('user_id', Auth::id())->paginate(10); I need to get all records where users id equals current authenticated users id. Works well without paginate() method.
Extending a bit Alexey's perfect answer :
Dispatch::all()=> Returns aCollection
Dispatch::all()->where()=> Returns aCollection
Dispatch::where()=> Returns aQuery
Dispatch::where()->get()=> Returns aCollection
Dispatch::where()->get()->where()=> Returns aCollection
You can only invoke "paginate" on a Query, not on a Collection.
And yes, it is totally confusing to have a where function for both Queries and Collections, working as close as they do, but it is what it is.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With