petercoles / Multilingual-Country-List

Laravel wrapper for generating country lookups and data objects using the awesome country-list data
MIT License
141 stars 33 forks source link

Search for specific country in specific language #6

Closed miggf closed 5 years ago

miggf commented 5 years ago

Hi,

How can I search for a specific country in a specific language.

Something like this

Countries::lookup(Lang::locale(), 'PT')

Should give the fallowing Output:

Portugal

I can find this method on the documentation, there is any method to do this? It would be really useful...

Thanks, Miguel Ferreira

petercoles commented 5 years ago

I like your use of Lang::locale() - I hadn't thought of that.

Since the lookup method returns a Laravel collection, this should give you what you're looking for:

Countries::lookup(Lang::locale())->get('PT')

petercoles commented 5 years ago

As an aside if you were planing to use more than one country from the collection, you could assign it to a local variable and then simply subscript it as shown below:

$lookup = Countries::lookup(Lang::locale());
echo $lookup['PT'];
echo $lookup['ES'];

I guess you could subscript the initial lookup method too, Countries::lookup(Lang::locale())['PT'], but that's a bit ugly :).