[英]Laravel 5 - Call to undefined method Illuminate\Database\Eloquent\Collection::Paginate()
I'm having an error我有一个错误
Call to undefined method Illuminate\Database\Eloquent\Collection::Paginate()调用未定义的方法 Illuminate\Database\Eloquent\Collection::Paginate()
I've been doing this:我一直在这样做:
public function index ()
{
$articles = Article::latest('published_at')->published()->get()->paginate(5);
$articlesLink = $articles->render();
return view('articles.index', compact('articles', 'articlesLink'));
}
Try changing尝试改变
$articles = Article::latest('published_at')->published()->get()->paginate(5);
to到
$articles = Article::latest('published_at')->published()->paginate(5);
By calling ->get()
, you'd be getting a Collection
object back, and there is no paginate()
method in the Collection
object, hence the error.通过调用->get()
,你会得到一个Collection
对象返回,并没有paginate()
方法的Collection
对象,因此错误。
public function index () { // you => $articles = Article::latest('published_at')->published()->get()->paginate(5); // me => $articles = Article::latest('published_at')->latest()->paginate(5); // Unnecessary $articlesLink = $articles->render(); return view('articles.index', compact('articles')); }
please remove get() from the query.请从查询中删除 get()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.