繁体   English   中英

分页问题Laravel 5.6

[英]Paginate Issue Laravel 5.6

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

我的数据库查询不正确吗? 我正在按照文档进行创建。 另请阅读,使用分页时需要删除->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 

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM