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

我有一个错误

调用未定义的方法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方法,因此会出现错误。

Laravel WHERE查询单列结果 - php

我有以下控制器,应该返回所有尚未验证的用户。public function getUserRequests() { $userRequests = User::where('status' ,"Not Verified"); foreach($userRequests as $user) { echo $user-&g…

Laravel 5排序具有关系的雄辩模型 - php

我有一个要基于关系属性进行排序的模型。主模型Resultado具有类型respondente的关系belongsTo,而respondente具有关系usuario。我想获取具有这些关系的Resultado并按usuario name属性(列)对结果进行排序。我试过了$resultados = Diagnostico\Resultado::with(…

Laravel-使用雄辩的语言在开始日期和结束日期之间选择行 - php

我想将此查询转换为雄辩的laravel,select * from schedule where (now() between start_date and end_date); 我尝试使用whereBetween,但是出现了一些错误。$schedule = Schedule::whereBetween(Carbon::now(), ['start…

Laravel Nova自指关系 - php

在Laravel中,如果要创建自引用关系,可以执行以下操作:class Post extends Eloquent { public function parent() { return $this->belongsTo('Post', 'parent_id'); } public function childr…

Laravel雄辩的查询JSON列与在哪里? - php

我在查询json列时遇到问题。以前我的代码是$query->whereIn('user', $users); 现在,我已将数据库类型更改为JSON列,并尝试修改新版本的代码。在RAW MYSQL中,这有效JSON_CONTAINS(user, '"tom","Bill"')…