src/Traits/CastsTrait.php
private function castField($option, $value)
    {
        $casts = $this->casts;

        if (!isset($casts[$option])) {
            return $value;
        }

        $cast = $casts[$option];

        if (is_null($value) || is_null($cast)) {
            return $value;
        }

        if (is_array($cast)) {
            return $this->complexListCast($value, $cast);
        }

        switch ($cast) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'list':
                return $this->castToList($value);
            default:
                return $this->castToObject($value, $cast);
        }
    }
private function castField($option, $value)
    {
        $casts = $this->casts;

        if (!isset($casts[$option])) {
            return $value;
        }

        $cast = $casts[$option];

        if (is_null($value) || is_null($cast)) {
            return $value;
        }

        if (is_array($cast)) {
            return $this->complexListCast($value, $cast);
        }

        switch ($cast) {
            case 'int':
            case 'integer':
                return (int) $value;
            case 'real':
            case 'float':
            case 'double':
                return (float) $value;
            case 'string':
                return (string) $value;
            case 'bool':
            case 'boolean':
                return (bool) $value;
            case 'list':
                return $this->castToList($value);
            default:
                return $this->castToObject($value, $cast);
        }
    }
private function castField ( $ option , $ value ) { $ casts = $ this -> casts ; if ( ! isset ( $ casts [ $ option ] ) ) { return $ value ; } $ cast = $ casts [ $ option ] ; if ( is_null ( $ value ) || is_null ( $ cast ) ) { return $ value ; } if ( is_array ( $ cast ) ) { return $ this -> complexListCast ( $ value , $ cast ) ; } switch ( $ cast ) { case 'int' : case 'integer' : return ( int ) $ value ; case 'real' : case 'float' : case 'double' : return ( float ) $ value ; case 'string' : return ( string ) $ value ; case 'bool' : case 'boolean' : return ( bool ) $ value ; case 'list' : return $ this -> castToList ( $ value ) ; default : return $ this -> castToObject ( $ value , $ cast ) ; } }
Casts the field

@param $option
@param $value
@return bool|float|mixed|ListObject|string
Casts the field