【问题标题】:Method render does not exist laravel pagination方法render不存在laravel分页
【发布时间】:2016-07-14 15:08:15
【问题描述】:
$page = Question::paginate(10);
dd($page);

这里的分页效果很好,但是当我将分页与其他模型关系一起使用时,它会产生分页结果,但分页链接不会出现,因为它会产生错误

 $questions = Course::with(['questions' => function($query){
                $query->paginate(10);
            },'questions.subjects','questions.years'])
            ->where("status",1)
            ->where(function ($query) use ($course) {
                $query->orWhere('course', '=', $course)
                    ->orWhere('slug', '=', $course);
            })->get();

错误:

 BadMethodCallException in Macroable.php line 81:
    Method render does not exist.

这里缺少什么。

【问题讨论】:

    标签: php laravel-5 pagination laravel-paginate


    【解决方案1】:

    Paginate 应该在查询结束时使用,而不是在关系中:

    $questions = Course::with(['questions','questions.subjects','questions.years'])
            ->where("status",1)
            ->where(function ($query) use ($course) {
                $query->orWhere('course', '=', $course)
                    ->orWhere('slug', '=', $course);
            })->paginate(10);
    

    由于您没有对主要结果集进行分页,因此您会收到 Method render does not exist 错误。

    【讨论】:

    • 谢谢,但我想在问题课上进行分页,而不是在课程中,所以我为分页做了什么。
    猜你喜欢
    • 2020-03-22
    • 2018-06-17
    • 2018-06-19
    • 1970-01-01
    • 2019-03-06
    • 1970-01-01
    • 2019-10-02
    • 2017-07-11
    • 2016-11-05
    相关资源
    最近更新 更多