private static function buildCastedAttributes($model, &$result, $method = null)
    {
        $model_name = 'self';
        $name_append = '';

        if (!is_null($method)) {
            $model_name = $method;
            $name_append = $method.'.';
        }

        // ModelSchema implementation gives us better data.
        if (class_exists('HnhDigital\ModelSchema\Model')
            && $model instanceof \HnhDigital\ModelSchema\Model) {

            // Build attributes off the schema.
            foreach ($model->getSchema() as $name => $config) {
                $result[$name_append.$name] = [
                    'name'              => $name,
                    'title'             => Arr::get($config, 'title', $name),
                    'attributes'        => [sprintf('%s.%s', $model->getTable(), $name)],
                    'filter'            => self::convertCast(Arr::get($config, 'cast')),
                    'model'             => &$model,
                    'model_name'        => $model_name,
                    'source_model'      => Arr::get($config, 'model'),
                    'source_model_key'  => Arr::get($config, 'model_key', null),
                    'source_model_name' => Arr::get($config, 'model_name', 'display_name'),
                ];
            }

            return;
        }

        // Build attributes off the specified casts.
        foreach ($model->getCasts() as $name => $cast) {
            $result[$name_append.$name] = [
                'name'       => $name,
                'title'      => $name,
                'attributes' => [sprintf('%s.%s', $model->getTable(), $name)],
                'filter'     => self::convertCast($cast),
                'model'      => &$model,
                'model_name' => $model_name,
            ];
        }
    }