PHPackages                             ewertondaniel/laravel-rest-countries - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ewertondaniel/laravel-rest-countries

ActiveLibrary[API Development](/categories/api)

ewertondaniel/laravel-rest-countries
====================================

Laravel package to fetch country data from RestCountries API

v2.0.0(5mo ago)0403↓31.3%MITPHPPHP ^8.2

Since Nov 26Pushed 5mo agoCompare

[ Source](https://github.com/EwertonDaniel/laravel-rest-countries)[ Packagist](https://packagist.org/packages/ewertondaniel/laravel-rest-countries)[ RSS](/packages/ewertondaniel-laravel-rest-countries/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Laravel REST Countries
======================

[](#laravel-rest-countries)

A Laravel package to consume the [REST Countries](https://restcountries.com/) API.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10, 11 or 12

Installation
------------

[](#installation)

```
composer require ewertondaniel/laravel-rest-countries
```

The service provider will be automatically registered.

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=rest-countries-config
```

Available environment variables:

```
REST_COUNTRIES_URL=https://restcountries.com/v3.1
REST_COUNTRIES_LOG_CHANNEL=stack
REST_COUNTRIES_HTTP_VERIFY=false
REST_COUNTRIES_HTTP_TIMEOUT=30
```

Usage
-----

[](#usage)

### Via Facade

[](#via-facade)

```
use EwertonDaniel\RestCountries\Facades\RestCountries;
use EwertonDaniel\RestCountries\Enums\CountryField;

// Get all countries (default fields: name, cca2)
$countries = RestCountries::getAll();

// With specific fields
$countries = RestCountries::getAll([
    CountryField::Name,
    CountryField::Capital,
    CountryField::Population,
]);

// Get by code
$country = RestCountries::getByCode('BR');
echo $country->name->common;          // Brazil
echo $country->capital->first()->name; // Brasília

// Get by name
$countries = RestCountries::getByName('brazil');

// Get by region
$countries = RestCountries::getByRegion('americas');
```

### Via Dependency Injection

[](#via-dependency-injection)

```
use EwertonDaniel\RestCountries\Contracts\RestCountriesInterface;

class CountryController
{
    public function __construct(
        private RestCountriesInterface $restCountries
    ) {}

    public function index()
    {
        return $this->restCountries->getAll();
    }
}
```

Available Methods
-----------------

[](#available-methods)

MethodReturnDescription`getAll($fields)``Collection`Get all countries`getIndependent($status, $fields)``Collection`Get independent countries`getByName($name, $fields)``Collection`Search by name`getByFullName($name, $fields)``Country`Search by full name`getByCode($code, $fields)``Country`Search by code`getByCodes($codes, $fields)``Collection`Search by list of codes`getByCurrency($currency, $fields)``Collection`Search by currency`getByDemonym($demonym, $fields)``Collection`Search by demonym`getByLanguage($language, $fields)``Collection`Search by language`getByCapital($capital, $fields)``Collection`Search by capital`getByCallingCode($code, $fields)``Collection`Search by calling code`getByRegion($region, $fields)``Collection`Search by region`getBySubregion($subregion, $fields)``Collection`Search by subregion`getByTranslation($translation, $fields)``Collection`Search by translationCountry Object
--------------

[](#country-object)

All properties that were previously arrays are now typed Collections of DTOs for better type safety and autocompletion.

```
$country = RestCountries::getByCode('DE');

// Name
$country->name->common;                    // Germany
$country->name->official;                  // Federal Republic of Germany
$country->name->nativeName['deu']->common; // Deutschland

// Codes
$country->cca2;                            // DE
$country->cca3;                            // DEU
$country->ccn3;                            // 276
$country->cioc;                            // GER

// Region
$country->region;                          // Europe
$country->subregion;                       // Western Europe

// Population & Area
$country->population;                      // 83491249
$country->area;                            // 357114.0

// TLD (Collection)
$country->tld->first()->domain;            // .de
$country->tld->pluck('domain')->toArray(); // ['.de']

// Capital (Collection)
$country->capital->first()->name;          // Berlin
$country->capital->pluck('name')->toArray(); // ['Berlin']

// Languages (Collection)
$country->languages->first()->code;        // deu
$country->languages->first()->name;        // German

// Borders (Collection)
$country->borders->first()->countryCode;   // AUT
$country->borders->pluck('countryCode')->toArray(); // ['AUT', 'BEL', 'CZE', ...]

// Currencies (Collection)
$country->currencies->first()->code;       // EUR
$country->currencies->first()->name;       // Euro
$country->currencies->first()->symbol;     // €

// Calling code (Idd)
$country->idd->root;                       // +4
$country->idd->suffixes;                   // ['9']
$country->idd->getFullCode();              // +49

// Coordinates (Coordinates)
$country->coordinates->latitude;           // 51.0
$country->coordinates->longitude;          // 9.0
$country->getLatitude();                   // 51.0
$country->getLongitude();                  // 9.0

// Timezones (Collection)
$country->timezones->first()->value;       // UTC+01:00
$country->timezones->pluck('value')->toArray(); // ['UTC+01:00']

// Continents (Collection)
$country->continents->first()->name;       // Europe

// Gini Index (Collection)
$country->gini->first()->year;             // 2016
$country->gini->first()->value;            // 31.9

// AltSpellings (Collection)
$country->altSpellings->first()->name;     // DE

// Flag
$country->flag;                            // 🇩🇪
$country->flags->png;                      // https://flagcdn.com/w320/de.png
$country->flags->svg;                      // https://flagcdn.com/de.svg
$country->flags->alt;                      // The flag of Germany

// Coat of Arms
$country->coatOfArms->png;                 // https://mainfacts.com/media/images/coats_of_arms/de.png
$country->coatOfArms->svg;                 // https://mainfacts.com/media/images/coats_of_arms/de.svg

// Maps
$country->maps->googleMaps;                // https://goo.gl/maps/...
$country->maps->openStreetMaps;            // https://www.openstreetmap.org/...

// Capital Info (CapitalInfo with Coordinates)
$country->capitalInfo->coordinates->latitude;  // 52.52
$country->capitalInfo->coordinates->longitude; // 13.4
$country->capitalInfo->getLatitude();          // 52.52
$country->capitalInfo->getLongitude();         // 13.4

// Demonyms (Collection)
$country->demonyms->firstWhere('language', 'eng')->male;   // German
$country->demonyms->firstWhere('language', 'eng')->female; // German

// Translations (Collection)
$country->translations->firstWhere('language', 'por')->common;   // Alemanha
$country->translations->firstWhere('language', 'por')->official; // República Federal da Alemanha

// Car
$country->car->signs;                      // ['DY']
$country->car->side;                       // right

// Postal Code
$country->postalCode?->format;             // #####
$country->postalCode?->regex;              // ^(\d{5})$

// Other
$country->independent;                     // true
$country->unMember;                        // true
$country->status;                          // officially-assigned
$country->landlocked;                      // false
$country->startOfWeek;                     // monday
$country->fifa;                            // GER
```

Data Transfer Objects (DTOs)
----------------------------

[](#data-transfer-objects-dtos)

All data is returned as strongly-typed DTOs:

DTOPropertiesDescription`Country`All propertiesMain country object`CountryName``common`, `official`, `nativeName`Country name`NativeName``official`, `common`Native name`Tld``domain`Top-level domain`Capital``name`Capital city`Language``code`, `name`Language`Border``countryCode`Border country code`Currency``code`, `name`, `symbol`Currency`Idd``root`, `suffixes`International dialing code`Coordinates``latitude`, `longitude`Geographic coordinates`Timezone``value`Timezone`Continent``name`Continent`Gini``year`, `value`Gini index`AltSpelling``name`Alternative spelling`Demonym``language`, `male`, `female`Demonym`Translation``language`, `official`, `common`Translation`Flags``png`, `svg`, `alt`Flag URLs`CoatOfArms``png`, `svg`Coat of arms URLs`Maps``googleMaps`, `openStreetMaps`Map URLs`Car``signs`, `side`Car/traffic info`CapitalInfo``coordinates`Capital coordinates`PostalCode``format`, `regex`Postal code formatDocumentation by Endpoint
-------------------------

[](#documentation-by-endpoint)

- [All Countries](docs/all.md)
- [Search by Code](docs/code.md)
- [Search by List of Codes](docs/codes.md)
- [Search by Name](docs/name.md)
- [Search by Full Name](docs/full-name.md)
- [Search by Currency](docs/currency.md)
- [Search by Language](docs/language.md)
- [Search by Capital](docs/capital.md)
- [Search by Region](docs/region.md)
- [Search by Subregion](docs/subregion.md)
- [Search by Demonym](docs/demonym.md)
- [Search by Translation](docs/translation.md)
- [Search by Independent](docs/independent.md)
- [Filter Response (Fields)](docs/fields.md)

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance70

Regular maintenance activity

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

173d ago

Major Versions

v1.0.0 → v2.0.02025-11-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/735b1ba4cf3c6a19b0e75524cd090d21f13a8936799387c579933d2b99789f26?d=identicon)[ewertondaniel](/maintainers/ewertondaniel)

---

Top Contributors

[![EwertonDaniel](https://avatars.githubusercontent.com/u/42904786?v=4)](https://github.com/EwertonDaniel "EwertonDaniel (2 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/ewertondaniel-laravel-rest-countries/health.svg)

```
[![Health](https://phpackages.com/badges/ewertondaniel-laravel-rest-countries/health.svg)](https://phpackages.com/packages/ewertondaniel-laravel-rest-countries)
```

###  Alternatives

[skagarwal/google-places-api

Google Places Api

1913.0M8](/packages/skagarwal-google-places-api)[dcblogdev/laravel-microsoft-graph

A Laravel Microsoft Graph API (Office365) package

168285.5k1](/packages/dcblogdev-laravel-microsoft-graph)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[grantholle/powerschool-api

A Laravel package to make interacting with PowerSchool less painful.

1715.6k1](/packages/grantholle-powerschool-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
