[英]Call to undefined method Illuminate\Database\Eloquent\Collection::save() laravel
[英]Laravel 5 - Call to undefined method Illuminate\Database\Eloquent\Collection::Paginate()
我有一個錯誤
調用未定義的方法 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'));
}
嘗試改變
$articles = Article::latest('published_at')->published()->get()->paginate(5);
到
$articles = Article::latest('published_at')->published()->paginate(5);
通過調用->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')); }
請從查詢中刪除 get()。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.