0

想知道是否有人可以检查一下并让我知道我做错了什么。我正在尝试对数据库查询使用分页并将其呈现在我的视图中。

我的数据库查询不正确吗?我正在按照文档来创建它。->get()另请阅读我在使用分页时需要删除。

这就是我认为错误的原因:{{$item->paginate(4)}},如果我使用也会发生同样的情况{{$item->links(4)}}

如果我从控制器中的查询中删除分页,一切都会好起来的..?

这是我正在使用的。

控制器:

        public function index()
{
   // $news = DB::table('news')->orderBy('id', 'DESC')->paginate(4);
    $news = DB::table('news')->select('id','title','description','listing_image','created_at','updated_at')->orderBy('id', 'DESC')->paginate(4);
    return view('news.index',compact('news'));
}

查看:(出现错误:调用未定义的方法 stdClass::paginate()

@if ($news->count())
@foreach($news as $item)
...html
 @if ($item->listing_image)
...more html

    @else
    @endif 

... more html

@endforeach

{{$item->paginate(4)}}

@endif 
4

1 回答 1

0

将 {{$item->paginate(4)}} 更改为 {{ $news->links() }}

于 2018-03-30T06:58:42.157 回答