mardi 30 avril 2019

Problem with Eloquent query filtering by value 0 in tinyint field

I have a user filter that filters by name, email and user type (admin or regular user)

I´m using eloquent query builder, and the field in the database is tinyint with values 0 for regular user and 1 for admin.

When trying to filter by regular user (0) I get all the users including the admins. And when I filter by admin I get the admins.

So somehow filtering by 0 returns all usertypes.

This is the query I´m using:

`

 * Scope a query to requested filters.
 *
 * @param \Illuminate\Database\Eloquent\Builder $query
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function scopeFilter($query)
{

    if(request('usertype')){

        $query->where('admin', request('usertype'));

    }

    return $query->orderBy('name', 'ASC');
}`

Can someone help?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire