enadabuzaid/country-data

Laravel package for country information (config-based, reusable, and localized)

Installs: 1 056

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/enadabuzaid/country-data

1.0.0 2025-06-05 14:31 UTC

This package is auto-updated.

Last update: 2025-09-12 13:03:18 UTC


README

A clean and reusable Laravel package for accessing comprehensive country information โ€” including localized names, flags, dial codes, currencies, timezones, and more โ€” all stored in a config/countries.php file for maximum performance.

๐Ÿ‡ฏ๐Ÿ‡ด Built with multilingual support, region filters, and helper methods โ€” ideal for dropdowns, admin panels, and international applications.

โœ… Features

  • ๐Ÿ“ฆ Publishable country list as config/countries.php
  • ๐ŸŒ Multilingual support (English and Arabic)
  • ๐ŸŒ Filters for Arab, Gulf, Muslim-majority, Continents, and more
  • ๐Ÿ“ž Dial codes with emoji flags and SVG URLs
  • ๐Ÿ” Search countries by name, code, or filter
  • ๐Ÿงฉ Helper formatters for frontend select menus
  • โšก Laravel-native config access (uses config() and config:cache)

๐Ÿš€ Installation

Add the package locally:

composer require enad/country-data

Publish the config file:

php artisan vendor:publish --tag=country-data

This will copy countries.php into your Laravel app's config folder:

config('countries');

๐Ÿ“˜ Documentation

๐Ÿ”„ Available Static Methods

use CountryData; // via Facade
Method Description
getArabCountries() Returns all Arab countries
getGulfCountries() Returns Gulf Cooperation Council countries
getByFilter('muslim-majority') Returns countries by custom filter
getByCode('SA') Gets full country data by code
searchByName('Jordan') Finds country by name in English or Arabic
getName('JO', 'ar') Returns the name of a country in a specific locale
getFlag('JO') Returns the flag emoji
getDialCodes(true) Returns list of dial codes, optionally with flags
getSelectOptions('ar') Returns array for select dropdowns (label + value)

๐Ÿ“ž Example: Get Dial Codes with Flags

CountryData::getDialCodes(true);

Returns:

[
  ['code' => 'JO', 'dial' => '+962', 'flag' => '๐Ÿ‡ฏ๐Ÿ‡ด', 'flag_url' => 'https://flagcdn.com/jo.svg'],
  ...
]

๐ŸŒ Example: Get Arab Countries

CountryData::getArabCountries();

๐Ÿ” Example: Search by Arabic Name

CountryData::searchByName('ุงู„ุณุนูˆุฏูŠุฉ', 'ar');

๐ŸŒ Example: Select Options for Vue/React

CountryData::getSelectOptions('en');
// => [ ['label' => 'Jordan', 'value' => 'JO'], ... ]

๐Ÿง  Extensible Filters

Available filters on countries include:

  • arab
  • gulf
  • muslim-majority
  • middle-east
  • asia, africa, europe, north-america, etc.

๐Ÿ“‚ File Structure

config/
โ””โ”€โ”€ countries.php       # Published config data
src/
โ”œโ”€โ”€ CountryData.php     # All logic methods
โ”œโ”€โ”€ Facades/CountryData.php
โ””โ”€โ”€ CountryDataServiceProvider.php

๐Ÿงช Coming Soon

  • getByContinent('Asia')
  • getSelectOptionsWithFlags()
  • country-data:export-json command
  • Optional database support

๐Ÿ“„ License

MIT โ€” built by @enadabuzaid