src/Metable.php
public function scopeOrderByMetaNumeric(Builder $q, string $key, string $direction = 'asc', $strict = false)
    {
        $table = $this->joinMetaTable($q, $key, $strict ? 'inner' : 'left');
        $direction = strtolower($direction) == 'asc' ? 'asc' : 'desc';
        $field = $q->getQuery()->getGrammar()->wrap("{$table}.value");

        $q->orderByRaw("cast({$field} as decimal) $direction");
    }
public function scopeOrderByMetaNumeric(Builder $q, string $key, string $direction = 'asc', $strict = false)
    {
        $table = $this->joinMetaTable($q, $key, $strict ? 'inner' : 'left');
        $direction = strtolower($direction) == 'asc' ? 'asc' : 'desc';
        $field = $q->getQuery()->getGrammar()->wrap("{$table}.value");

        $q->orderByRaw("cast({$field} as decimal) $direction");
    }
public function scopeOrderByMetaNumeric ( Builder $ q , string $ key , string $ direction = 'asc' , $ strict = false ) { $ table = $ this -> joinMetaTable ( $ q , $ key , $ strict ? 'inner' : 'left' ) ; $ direction = strtolower ( $ direction ) == 'asc' ? 'asc' : 'desc' ; $ field = $ q -> getQuery ( ) -> getGrammar ( ) -> wrap ( "{$table}.value" ) ; $ q -> orderByRaw ( "cast({$field} as decimal) $direction" ) ; }
Query scope to order the query results by the numeric value of an attached meta.

@param Builder $q
@param string  $key
@param string  $direction
@param bool    $strict    if true, will exclude records that do not have meta for the provided `$key`.

@return void
Query scope to order the query results by the numeric value of an attached meta .