Add pagination to one to many relationsship
i have a query like below,
$testdetail = Test::with(['offlineconvertedtests.userdet.userregistereddetail' => function($q) use($coursedetails) {
$q->where('course_id',$coursedetails->course_id)
->whereNotNull('registration_number');
}])->with(['offlineconvertedtests.roomslotdet'])->where('test_code',$testcode)->where('course',$coursedetails->course_id)->first();
i tried to add pagination like below,
$convertedtests = $testdetail->offlineconvertedtests()->paginate(30);
but i am not getting all relationship data. (Example: i am not getting offlineconvertedtests.roomslotdet data
How to apply pagination ?
I'm not sure you can do it that way.
I take it you are talking about a show view here?
If so I would first fetch the master into one variable and then all the children.
Something like this.
public function(Author $author)
{
$books = Book::where('author_id', $author->id)->paginate(20);
return view('authors.show')
->with([
'author' => $author,
'books' => $books
]);
}
@Tray2 Thank you for the reply here it is one to many relation i have to apply pagination for relationship data i tired like below,
$convertedtests = $testdetail->offlineconvertedtests()->with(['userdet.userregistereddetail' => function($q) use($coursedetails) {
$q->where('course_id',$coursedetails->course_id)
->whereNotNull('registration_number');
}])->paginate(30);
this one is working fine. can you please check this and confirm if it s right way to do that?
@Deekshith Does it work the way you want it to? If so go with it.
Please or to participate in this conversation.