$queryStudent = Student::whereIsActive(1);
$bachelorStudents = $queryStudent->whereCourseId(3)->get();
$masterStudents = $queryStudent->whereCourseId(4)->get();
Dec 7, 2015
5
Level 8
Assign a query to variable to then perform two separate queries?
Hey everyone, just wondering if I can start an eloquent query, assign it to a variable then continue using the variable for two separate queries without them conflicting with one another. A simple example:
$students = $this->student
// more query stuff
->where('is_active', 1);
$bachelorStudents = $students
->where('course_id', 3)
->get();
$masterStudents = $students
->where('course_id', 4)
->get();
or would I need to do:
$bachelorStudents = $this->student
->where('course_id', 3)
->get();
$masterStudents = $this->student
->where('course_id', 4)
->get();
I always thought I could do the former, but some of my results appear to show I can't but I am open to believe that if you can do it then perhaps I'm doing something wrong.
Please or to participate in this conversation.