public function format($mode, $name, $data)
    {
        if ($mode === 'cast') {
            throw new InvalidArgumentException("Use `Schema::cast()` to perform casting.");
        }
        if (!isset($this->_columns[$name])) {
            // Formatting non defined columns or relations doesn't make sense, bailing out.
            return $this->convert($mode, '_default_', $data, []);
        }
        $column = $this->_columns[$name];
        $isNull = $data === null;
        $type = $isNull ? 'null' : $this->type($name);

        if (!$column['array']) {
            $data = $this->convert($mode, $type, $data, $column);
        } else {
            $data = Collection::format($mode, $data);
        }
        if (!$isNull && !empty($column['format'])) {
            $data = $this->convert($mode, $column['format'], $data, $column);
        }
        return $data;
    }
public function format($mode, $name, $data)
    {
        if ($mode === 'cast') {
            throw new InvalidArgumentException("Use `Schema::cast()` to perform casting.");
        }
        if (!isset($this->_columns[$name])) {
            // Formatting non defined columns or relations doesn't make sense, bailing out.
            return $this->convert($mode, '_default_', $data, []);
        }
        $column = $this->_columns[$name];
        $isNull = $data === null;
        $type = $isNull ? 'null' : $this->type($name);

        if (!$column['array']) {
            $data = $this->convert($mode, $type, $data, $column);
        } else {
            $data = Collection::format($mode, $data);
        }
        if (!$isNull && !empty($column['format'])) {
            $data = $this->convert($mode, $column['format'], $data, $column);
        }
        return $data;
    }
public function format ( $ mode , $ name , $ data ) { if ( $ mode === 'cast' ) { throw new InvalidArgumentException ( "Use `Schema::cast()` to perform casting." ) ; } if ( ! isset ( $ this -> _columns [ $ name ] ) ) { // Formatting non defined columns or relations doesn't make sense, bailing out. return $ this -> convert ( $ mode , '_default_' , $ data , [ ] ) ; } $ column = $ this -> _columns [ $ name ] ; $ isNull = $ data === null ; $ type = $ isNull ? 'null' : $ this -> type ( $ name ) ; if ( ! $ column [ 'array' ] ) { $ data = $ this -> convert ( $ mode , $ type , $ data , $ column ) ; } else { $ data = Collection :: format ( $ mode , $ data ) ; } if ( ! $ isNull && ! empty ( $ column [ 'format' ] ) ) { $ data = $ this -> convert ( $ mode , $ column [ 'format' ] , $ data , $ column ) ; } return $ data ; }
Formats a value according to a field definition.

@param   string $mode The format mode (i.e. `'array'` or `'datasource'`).
@param   string $name The field name.
@param   mixed  $data The data to format.
@return  mixed        The formated value.
Formats a value according to a field definition .