[英]Paginate Issue Laravel 5.6
Was wondering if someone could check this out and let me know what I'm doing wrong. 想知道是否有人可以检查一下,让我知道我做错了什么。 I'm trying to use paginate on a database query and render it in my view.
我正在尝试对数据库查询使用分页并在我的视图中呈现它。
Is my DB query incorrect? 我的数据库查询不正确吗? I was following the docs to create it.
我正在按照文档进行创建。 Also read that I needed to remove
->get()
when using paginate. 另请阅读,使用分页时需要删除
->get()
。
This is what is giving the error on my view: {{$item->paginate(4)}}
, same happens if I use {{$item->links(4)}}
这就是给我的视图带来错误的原因:
{{$item->paginate(4)}}
,如果我使用{{$item->links(4)}}
Everything renders fine if I remove paginate from the query in the controller..? 如果我从控制器中的查询中删除分页,一切都会很好。
Here is what I'm working with. 这是我正在使用的。
Controller: 控制器:
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'));
}
View: ( Getting error: Call to undefined method stdClass::paginate() ) 查看:( 错误:调用未定义的方法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.