简体   繁体   English

Laravel 5 - 调用未定义的方法 Illuminate\Database\Eloquent\Collection::Paginate()

[英]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.

相关问题 调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: save()laravel - Call to undefined method Illuminate\Database\Eloquent\Collection::save() laravel Laravel:调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: where() - Laravel: Call to undefined method Illuminate\Database\Eloquent\Collection::where() Laravel 5:调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: exists() - Laravel 5: Call to undefined method Illuminate\Database\Eloquent\Collection::exists() Laravel 5调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: attach() - Laravel 5 Call to undefined method Illuminate\Database\Eloquent\Collection::attach() Laravel-eloquent:调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: where() - Laravel-eloquent: Call to undefined method Illuminate\Database\Eloquent\Collection::where() Laravel 5:无法使用分页,出现错误“调用未定义的方法 Illuminate\\Database\\Eloquent\\Collection::render()” - Laravel 5: not able to use pagination, I get error “Call to undefined method Illuminate\Database\Eloquent\Collection::render()” 调用未定义的方法Illuminate \\ Database \\ Eloquent \\ Collection :: useAsCallable()“ - Call to undefined method Illuminate\Database\Eloquent\Collection::useAsCallable()" 调用未定义的方法 Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::type() [Laravel] - Call to undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsTo::type() [Laravel] Laravel 分页 - 调用未定义的方法 Illuminate\\Database\\Eloquent\\Builder::links() - Laravel Pagination - Call to undefined method Illuminate\Database\Eloquent\Builder::links() Laravel 7.6 调用未定义的方法 Illuminate\Database\Eloquent\Builder::appends() - Laravel 7.6 Call to undefined method Illuminate\Database\Eloquent\Builder::appends()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM