protected function convertAttribute($attribute)
    {
        try {
            return (string) $attribute;
        } catch (\Exception $e) {
            switch (true) {
                // Handle DateTime attribute pass.
                case $attribute instanceof \DateTime:
                    return $attribute->format('Y-m-d H:i:s');

                // Handle callables.
                case $attribute instanceof \Closure:
                    return $this->convertAttribute($attribute());

                // Handle arrays using json by default or print_r if error occurred.
                case is_array($attribute):
                    $json = json_encode($attribute);

                    return json_last_error() === JSON_ERROR_NONE
                        ? $json
                        : print_r($attribute);

                // Handle all other object.
                case is_object($attribute):
                    return get_class($attribute);

                // For all unknown.
                default:
                    return '?';
            }
        }
    }
protected function convertAttribute($attribute)
    {
        try {
            return (string) $attribute;
        } catch (\Exception $e) {
            switch (true) {
                // Handle DateTime attribute pass.
                case $attribute instanceof \DateTime:
                    return $attribute->format('Y-m-d H:i:s');

                // Handle callables.
                case $attribute instanceof \Closure:
                    return $this->convertAttribute($attribute());

                // Handle arrays using json by default or print_r if error occurred.
                case is_array($attribute):
                    $json = json_encode($attribute);

                    return json_last_error() === JSON_ERROR_NONE
                        ? $json
                        : print_r($attribute);

                // Handle all other object.
                case is_object($attribute):
                    return get_class($attribute);

                // For all unknown.
                default:
                    return '?';
            }
        }
    }
protected function convertAttribute ( $ attribute ) { try { return ( string ) $ attribute ; } catch ( \ Exception $ e ) { switch ( true ) { // Handle DateTime attribute pass. case $ attribute instanceof \ DateTime : return $ attribute -> format ( 'Y-m-d H:i:s' ) ; // Handle callables. case $ attribute instanceof \ Closure : return $ this -> convertAttribute ( $ attribute ( ) ) ; // Handle arrays using json by default or print_r if error occurred. case is_array ( $ attribute ) : $ json = json_encode ( $ attribute ) ; return json_last_error ( ) === JSON_ERROR_NONE ? $ json : print_r ( $ attribute ) ; // Handle all other object. case is_object ( $ attribute ) : return get_class ( $ attribute ) ; // For all unknown. default : return '?' ; } } }
Convert attribute to string.

@param  mixed $attribute
@return string
Convert attribute to string .