我有错误
我一直在这样做:
public function index ()
{
$articles = Article::latest('published_at')->published()->get()->paginate(5);
$articlesLink = $articles->render();
return view('articles.index', compact('articles', 'articlesLink'));
}
最佳答案
尝试改变
$articles = Article::latest('published_at')->published()->get()->paginate(5);
至
$articles = Article::latest('published_at')->published()->paginate(5);
通过调用
->get()
,您将获得一个 Collection
对象,并且 paginate()
对象中没有 Collection
方法,因此出现错误。关于php - Laravel 5 - 调用未定义的方法 Illuminate\Database\Eloquent\Collection::Paginate(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37896069/