vendredi 29 septembre 2017

whereBetween() Eloquent returning wrong results

Hi 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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire