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
commitTranslation()must be static as well when you call it statically.TranslatedCountryCodes::getInstance()->commitTranslation();. But why do you pass something? The method has no arguments. You need to change it.public function commitTranslation(string $country) { return $this->translatedCodes[$country] ?? 'not found'; }.