I have a Eloquent query and I am using query scope. I have a km column in my table and I am passing kmFrom and KmTo values as post data. Now I am doing a eloquent whereBetween and its returning wrong results when I search for km.
For example if I pass kmFrom = 1000
and kmTo = 2000
. Its giving me results which are not in between these two values.
Eloquent:
Product::categoriesCategoryId($categoryId)
->km($kmFrom, $kmTo)->get();
Query Scope for the km:
public function scopeKm($query, $kmFrom, $kmTo)
{
if(($kmFrom) && ($kmTo)){
return $query->whereBetween('km', ["$kmFrom", "$kmTo"]);
}
return $query;
}
Please assist what wrong I am doing.
It's different approach to doing same thing
this will work same hope this will help you!