【问题标题】:Pagination in laravel not generating links on viewslaravel中的分页不会在视图上生成链接
【发布时间】:2015-07-27 13:35:22
【问题描述】:

我想在一页上显示所有博客,但想对它们进行分页。分页有效,但链接似乎没有出现在视图中。它一直向我显示此错误:

调用未定义的方法 Illuminate\Database\Eloquent\Collection::links()

代码如下:

public static function all()
{
  return \ExpoPost::with('attachment')->published()->type('post')->orderBy('post_date')->paginate(5);
}       

在视图中我正在尝试做这样的事情

@foreach($posts as $post)
  <p>{{$post->post_title}}</p>
@endforeach
<p>{{$posts->links()}}</p>

有人可以帮帮我吗?

【问题讨论】:

  • 看起来不错。如果你删除

    {{$posts->links()}}

    你的@foreach 会显示吗?
  • 是的,我的@foreach 工作正常

标签: php laravel-4 pagination


【解决方案1】:

问题是分页不适用于预加载。这个问题详解Laravel 4.1: How to paginate eloquent eager relationship?

因此,如果您想分页,则需要使用雄辩的“where”或流利的查询来更改您的查询。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 2021-08-03
    • 1970-01-01
    • 2014-05-28
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多