There's an example of apending links in the chapter on pagination. It's just an array.
Append values to pagination
I've being following Laracast for so long time and I am finally posting my first question.
I am working on a very dirty project, pretty much a mess and I am very limited with the changes that I can do.
I need to query students with exams and school and return the results in a pagination. It's pretty much simple up to here, but my problem is that each of the students have a field called flag and the flag for each of the students is a number from 1 to 3 it can also be null and in that case it will be taken as the number 1.
I need to count how many students have flag = 1 or null and also for all of the others meaning how many student have flag 2, how many flag 3. This need to happen before paginate since I need the total for the entire results and not only for the current page.
I have to add this value as property of the pagination since I still need to return all of the students in the same query or I would not mind to $appends flag_1, flag_2, flag_3 to each of the students and I could extract the value from the first student in that case.
This is pretty much what I have.
$exam = Exam::find(1);
$students = $exam->students->with('exam','school')->where('end_time', '<=', Carbon::now())
$flagOne = I need to find the students with flag = 1 or null;
$flagTwo = I need to find the students with flag = 2;
$flagThree = I need to find the students with flag = 3;
$students->paginate(10);
if you want to do it like that you can try this for example:
$query = $exam->students()->where('end_time', '<=', Carbon::now());
$countFlagOne = with(clone $query)->where('flag', 1)->orWhere('flag', null)->count();
$countFlagTwo = with(clone $query)->where('flag', 2)->count();
$countFlagThree = with(clone $query)->where('flag', 3)->count();
Please or to participate in this conversation.