我有错误
调用未定义的方法Illuminate \ Database \ Eloquent \ Collection :: Paginate()
我一直这样做:
public function index ()
{
$articles = Article::latest('published_at')->published()->get()->paginate(5);
$articlesLink = $articles->render();
return view('articles.index', compact('articles', 'articlesLink'));
}
答案 0 :(得分:4)
尝试更改
$articles = Article::latest('published_at')->published()->get()->paginate(5);
到
$articles = Article::latest('published_at')->published()->paginate(5);
通过调用->get()
,您将获得一个Collection
对象,并且paginate()
对象中没有Collection
方法,因此出错。
答案 1 :(得分:0)
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')); }