I have been struggling with this for efficiency purpose. Logically, this should work. But, once I call count() or get(), the 2nd usage does not work. If you see the following code, it'll become clear to you:
$query = Address::where('area_id',$area->id);
if($order === 'house_no')
$query->orderBy('house_no','ASC');
$query->join('members as m','addresses.member_id','=','m.id');
if($order === 'reg')
$query->orderBy('batch','ASC')->orderBy('reg','ASC');
if($types != '')
$query->whereIn('m.type', explode(',', $types));
$male = $query->where('m.gender','male')->get();
$female = $query->where('m.gender','female')->get(); //this does not work
As you can see, calling the $query variable in both the $male and $female should logically work. But I only get the result of the first call, it seems that once the count() or get() is called, the $query variable no longer does anything else.
I have also tried to store $query to two different variables for those two collections, but same result.
Any suggestions?
I could do the same thing twice but it would be inefficient (me thinks).
Thanks in advance!