With the getList() helper, you can fetch optimized country lists, perfect for populating dropdowns or similar elements.
use Lwwcas\LaravelCountries\Models\Country;
Country::getList()
->withNamesAndSlugs()
->get();
use Lwwcas\LaravelCountries\Models\Country;
Country::getList()
->withNamesSlugsAndFlags()
->get();
->withNamesAndSlugs() on Array version::: info You will need to convert the collection to an array.
You can achieve this by using Eloquent's ->toArray() method.
Country::getList()->withNamesAndSlugs()->get()->toArray();
:::
array:3 [▼
0 => array:8 [▼
"id" => 3 // [!code focus]
"uid" => "01J95Z2ZE5KYX1QJEXYVER62D1" // [!code focus]
"official_name" => "Islamic Emirate of Afghanistan" // [!code focus]
"iso_alpha_2" => "AF" // [!code focus]
"iso_alpha_3" => "AFG" // [!code focus]
"name" => "Afghanistan" // [!code focus]
"slug" => "afghanistan" // [!code focus]
"translations" => array:1 [▼ // [!code focus]
0 => array:5 [▼ // [!code focus]
"id" => 3 // [!code focus]
"lc_country_id" => 3 // [!code focus]
"name" => "Afghanistan" // [!code focus]
"slug" => "afghanistan" // [!code focus]
"locale" => "en" // [!code focus]
]
]
]
1 => array:8 [▶]
2 => array:8 [▶]
...
]
->withNamesSlugsAndFlags() on Array version::: info You will need to convert the collection to an array.
You can achieve this by using Eloquent's ->toArray() method.
Country::getList()->withNamesSlugsAndFlags()->get()->toArray();
:::
array:3 [▼
0 => array:9 [▼
"id" => 3 // [!code focus]
"uid" => "01J95Z2ZE5KYX1QJEXYVER62D1" // [!code focus]
"official_name" => "Islamic Emirate of Afghanistan" // [!code focus]
"iso_alpha_2" => "AF" // [!code focus]
"iso_alpha_3" => "AFG" // [!code focus]
"flag_emoji" => array:9 [▼ // [!code focus]
"css" => "\1F1E6\1F1EB" // [!code focus]
"hex" => "🇦🇫" // [!code focus]
"img" => "🇦🇫" // [!code focus]
"html" => "🇦🇫" // [!code focus]
"utf8" => "🇦🇫" // [!code focus]
"uCode" => "U+1F1E6 U+1F1EB" // [!code focus]
"utf16" => "\uD83C\uDDE6\uD83C\uDDEB" // [!code focus]
"decimal" => "🇦🇫" // [!code focus]
"shortcode" => ":flag-af:" // [!code focus]
] // [!code focus]
"name" => "Afghanistan" // [!code focus]
"slug" => "afghanistan" // [!code focus]
"translations" => array:1 [▼ // [!code focus]
0 => array:5 [▼ // [!code focus]
"id" => 3 // [!code focus]
"lc_country_id" => 3 // [!code focus]
"name" => "Afghanistan" // [!code focus]
"slug" => "afghanistan" // [!code focus]
"locale" => "en" // [!code focus]
] // [!code focus]
] // [!code focus]
]
1 => array:9 [▶]
2 => array:9 [▶]
...
]
How can I help you explore Laravel packages today?