0
votes
$page = Question::paginate(10);
dd($page);

Here the pagination working very well but when i use pagination with other models relations then its produce the paginate result but pagination links not appear because its produce error

 $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();

ERROR :

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

What is missing here.

1

1 Answers

0
votes

Paginate should be used at the end of a query, and not in relations:

$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);

Since you are not paginating the main result set, you get the Method render does not exist error.