Hello Guys,
So i'm trying to build a report system that takes in optional parameters from & to which are dates.
so this is the function,
$loans = new Loan();
if ($request->from && $request->to) {
$loans = $loans->whereBetween('created_at', [$request->from, $request->to]);
}
so i didn't call get or all on any of them, cause i want to use the variable and do different queries on them.
so the problem is if I dump the count of loans when the from and to parameters are passed, lets assume of a random date
dd($loans->count());
I get around 194 applications
but then when i create a new variable and use the loans variable to query other things,
$test = $loans->whereNotNull('user_id')->whereNull('underwriter_level_1_user_id')->count();
and i dump the count of the loans variable that was originally 194 right after that.
the count reduces to 134. cause of this test variable.
Does anyone know why this is happening and how i can get around this? I want to leave the loan variable open to any query i want, and i don't want to call the model every time, cause i'll have to pass the wherebetween for each of them, and this is an optional field