Laravel方法分页不存在 [英] Laravel Method paginate does not exist

查看:85
本文介绍了Laravel方法分页不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对模型结果进行分页,但是我收到方法分页不存在"的信息.这是我的代码:

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);

我需要获取所有记录,其中用户ID等于当前经过身份验证的用户ID.如果没有paginate()方法,效果很好.

I need to get all records where users id equals current authenticated users id. Works well without paginate() method.

推荐答案

您需要删除 all():

Dispatch::where('user_id', Auth::id())->paginate(10);

使用 all()时,您将从表中获取所有行并获得一个集合.然后,您正在使用收集方法 where()(而不是查询生成器方法 where()),然后尝试使用 paginate()方法,它不存在.

When you're using all() you get all the rows from the table and get a collection. Then you're using collection method where() (and not Query Builder method where()) and then you're trying to use paginate() method on the collection and it doesn't exist.

这篇关于Laravel方法分页不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆