public function nullIfEmpty($value, $key = null)
    {
        if (! is_null($key)) {
            $value = $this->fetchValueForKey($key, $value);
        }

        if (is_array($value)) {
            return $this->nullIfEmptyArray($key, $value);
        }

        if (is_bool($value)) {
            return $value;
        }

        return trim($value) === '' ? null : $value;
    }