public function scopeHasRoles(Builder $query, array $roles = []): Builder
    {
        $query->with('roles')->whereNotNull('users.id');

        if (! empty($roles)) {
            $query->whereHas('roles', function ($query) use ($roles) {
                $query->whereIn(Role::column('name'), $roles);
            });
        }

        return $query;
    }
public function scopeHasRoles(Builder $query, array $roles = []): Builder
    {
        $query->with('roles')->whereNotNull('users.id');

        if (! empty($roles)) {
            $query->whereHas('roles', function ($query) use ($roles) {
                $query->whereIn(Role::column('name'), $roles);
            });
        }

        return $query;
    }
public function scopeHasRoles ( Builder $ query , array $ roles = [ ] ) : Builder { $ query -> with ( 'roles' ) -> whereNotNull ( 'users.id' ) ; if ( ! empty ( $ roles ) ) { $ query -> whereHas ( 'roles' , function ( $ query ) use ( $ roles ) { $ query -> whereIn ( Role :: column ( 'name' ) , $ roles ) ; } ) ; } return $ query ; }
Search user based on keyword as roles.

@param  \Illuminate\Database\Eloquent\Builder  $query
@param  array  $roles

@return \Illuminate\Database\Eloquent\Builder
Search user based on keyword as roles .