Home > Blockchain >  How to get array data from Class
How to get array data from Class

Time:11-16

How can I retrive translations with country code from this class array and show it in my blade file? Lets say I have country code AF and then how I can return Afghanistan?

class TranslatedCountryCodes
{

    private        $translatedCodes = [];
    private static $instance;

    protected function __construct()
    {
        $this->translatedCodes = [
            'AF' => __('Afghanistan', 'countrycode', 'myproject'),
            'AX' => __('Aland Islands', 'countrycode', 'myproject')
        ];
    }

    public function commitTranslation()
    {
        return $this->translatedCodes;
    }

    /**
     * @return static
     */
    public static function getInstance()
    {
        if (is_null(static::$instance)) {
            static::$instance = new static();
        }

        return static::$instance;
    }
}

I have tried

TranslatedCountryCodes::commitTranslation('AF')

I've been looking up some helper functions but cant figure it out

CodePudding user response:

You could do:

TranslatedCountryCodes::getInstance()->commitTranslation()['AF']
  • Related