src/Metable.php
public function scopeWhereMetaNumeric(Builder $q, string $key, string $operator, $value)
    {
        // Since we are manually interpolating into the query,
        // escape the operator to protect against injection.
        $validOperators = ['<', '<=', '>', '>=', '=', '<>', '!='];
        $operator = in_array($operator, $validOperators) ? $operator : '=';
        $field = $q->getQuery()->getGrammar()->wrap($this->meta()->getRelated()->getTable().'.value');

        $q->whereHas('meta', function (Builder $q) use ($key, $operator, $value, $field) {
            $q->where('key', $key);
            $q->whereRaw("cast({$field} as decimal) {$operator} ?", [(float) $value]);
        });
    }
public function scopeWhereMetaNumeric(Builder $q, string $key, string $operator, $value)
    {
        // Since we are manually interpolating into the query,
        // escape the operator to protect against injection.
        $validOperators = ['<', '<=', '>', '>=', '=', '<>', '!='];
        $operator = in_array($operator, $validOperators) ? $operator : '=';
        $field = $q->getQuery()->getGrammar()->wrap($this->meta()->getRelated()->getTable().'.value');

        $q->whereHas('meta', function (Builder $q) use ($key, $operator, $value, $field) {
            $q->where('key', $key);
            $q->whereRaw("cast({$field} as decimal) {$operator} ?", [(float) $value]);
        });
    }
public function scopeWhereMetaNumeric ( Builder $ q , string $ key , string $ operator , $ value ) { // Since we are manually interpolating into the query, // escape the operator to protect against injection. $ validOperators = [ '<' , '<=' , '>' , '>=' , '=' , '<>' , '!=' ] ; $ operator = in_array ( $ operator , $ validOperators ) ? $ operator : '=' ; $ field = $ q -> getQuery ( ) -> getGrammar ( ) -> wrap ( $ this -> meta ( ) -> getRelated ( ) -> getTable ( ) . '.value' ) ; $ q -> whereHas ( 'meta' , function ( Builder $ q ) use ( $ key , $ operator , $ value , $ field ) { $ q -> where ( 'key' , $ key ) ; $ q -> whereRaw ( "cast({$field} as decimal) {$operator} ?" , [ ( float ) $ value ] ) ; } ) ; }
Query scope to restrict the query to records which have `Meta` with a specific key and numeric value.

Performs numeric comparison instead of string comparison.

@param Builder   $q
@param string    $key
@param string    $operator
@param int|float $value

@return void
Query scope to restrict the query to records which have Meta with a specific key and numeric value .