antonioribeiro/countries 如何直接从国家选择中获取货币符号?

antonioribeiro/countries How to get currency symbol directly from country selection?

我不确定这是否是包裹问题的正确渠道, 但是我正在使用这个包,https://github.com/antonioribeiro/countries。文档不是很清楚。

我可以用下面的代码得到货币符号,

$all = $countries->where('name.common', 'India')->first()->hydrateCurrencies()->currencies;

dd($all->INR->units->major->symbol);

但是在第二行代码中,我必须指定INR来获取符号。但是根据要求,我必须通过在 where 语句中指定选择哪个国家/地区来获得一个符号,

有人知道这个包裹吗?

谢谢,

您可以使用 ->first() 方法获取该国家/地区最常用的货币。

所以在你的例子中它会是

echo $all->first()->units->major->symbol;

我刚刚将 INR 替换为 first()