### Install Laravel ISO Countries Package Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Command to install the Laravel ISO Countries package using Composer. This command fetches the latest version of the package and its dependencies. ```bash composer require io238/laravel-iso-countries ``` -------------------------------- ### Laravel ISO Countries Configuration Example Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Example of the published configuration file for the Laravel ISO Countries package. It defines the supported locales for storing names (countries, languages, currencies) and the path for the SQLite database. ```php [ // Supported locales for names (countries, languages, currencies) 'locales' => [ 'en', 'de', 'fr', 'es', ], // Path for storing your own SQLITE database 'database_path' => database_path('iso-countries.sqlite'), ]; ``` -------------------------------- ### Laravel ISO Countries Relationships Example Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Demonstrates how to access relationships between Country, Language, and Currency models provided by the package. These examples show how to find related data such as official languages for a country or countries using a specific currency. ```php // Official languages spoken in Luxembourg ('LU') Country::find('LU')->languages; // Currencies used in Ghana ('GH') Country::find('GH')->currencies; // Countries that have Spanish ('es') as one of their official languages Language::find('es')->countries; // Countries that use the Euro ('EUR') as currency Currency::find('EUR')->countries; ``` -------------------------------- ### Run Package Tests (Bash) Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md A simple bash command to execute the test suite for the laravel-iso-countries package using Composer. This is typically used to verify the package's functionality after installation or modification. ```bash composer test ``` -------------------------------- ### Laravel ISO Language Model Example Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Example of retrieving a Language model by its ISO 639-1 code ('pt') and the structure of the returned model. It includes the language ID, ISO 639-2 codes, names in various locales, native name, language family, and a Wikipedia URL. ```php Country::find('pt'); Io238\ISOCountries\Models\Language { id: "pt", iso639_2: "por", iso639_2b: null, name: "{"en":"Portuguese","de":"Portugiesisch","fr":"portugais","es":"portugués"}", native_name: "Português", family: "Indo-European", wiki_url: "https://en.wikipedia.org/wiki/Portuguese_language", } ``` -------------------------------- ### Laravel ISO Currency Model Example Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Example of retrieving a Currency model by its ISO 4217 code ('COP') and the structure of the returned model. It includes the currency ID, names in various locales, plural name, symbol, native symbol, decimal digits, and rounding information. ```php Currency::find('COP'); Io238\ISOCountries\Models\Currency { id: "COP", name: "{"en":"Colombian Peso","de":"Kolumbianischer Peso","fr":"peso colombien","es":"peso colombiano"}", name_plural: "Colombian pesos", symbol: "CO$", symbol_native: "$", decimal_digits: 0, rounding: 0, } ``` -------------------------------- ### Laravel ISO Country Model Example Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Example of retrieving a Country model by its 2-letter ISO code ('AD') and the structure of the returned model. It includes details like alpha3 code, names in various locales, capital, TLD, calling code, region, population, coordinates, and area. ```php Country::find('AD'); Io238\ISOCountries\Models\Country { id: "AD", alpha3: "AND", name: "{"en":"Andorra","de":"Andorra","fr":"Andorre","es":"Andorra"}", native_name: "Andorra", capital: "Andorra la Vella", top_level_domain: ".ad", calling_code: "376", region: "Europe", subregion: "Southern Europe", population: 78014, lat: 42.5, lon: 1.5, demonym: "Andorran", area: 468, } ``` -------------------------------- ### Laravel ISO Countries Database Ignore Configuration Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Example `.gitignore` configuration to ensure the generated SQLite database file for the ISO Countries package is tracked by Git. This is typically done by excluding all `.sqlite` files except for the specific `iso-countries.sqlite`. ```gitignore # database/.gitignore *.sqlite* !iso-countries.sqlite ``` -------------------------------- ### Retrieve Countries Using a Currency (PHP) Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md This snippet shows how to find all countries that use a specific currency, such as EUR. It utilizes the Currency model and its 'countries' relationship, followed by a pluck operation to get country names. It requires the 'Currency' model. ```php Currency::find('EUR')->countries->pluck('name'); ``` -------------------------------- ### Publish Laravel ISO Countries Configuration Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Command to publish the configuration file for the Laravel ISO Countries package. This allows customization of supported locales and the database path. ```bash php artisan vendor:publish --provider="Io238\ISOCountries\ISOCountriesServiceProvider" --tag="config" ``` -------------------------------- ### Set Application Locale and Retrieve Localized Country Names (PHP) Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Demonstrates how to set the application's locale and then retrieve a collection of country names localized to that locale. It shows ordering countries by population within a specific region. The package leverages spatie/laravel-translatable for localization. ```php app()->setLocale('fr'); Io238\ISOCountries\Models\Country::where('region', 'Africa')->orderByDesc('population')->limit(10)->pluck('name'); ``` -------------------------------- ### Rebuild Laravel ISO Countries Database Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Artisan command to rebuild the SQLite database for the Laravel ISO Countries package. This is necessary after changing the configuration to include different language translations. ```bash php artisan db:seed countries:build ``` -------------------------------- ### Attribute Casting for Currency Model (PHP) Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md Illustrates how to use attribute casting in a Laravel model to automatically cast an ISO currency code to the Currency model. This allows easy access to all meta-data associated with the currency. It also shows how to update the currency field using either the ISO code string or the Currency model instance. ```php use Io238\ISOCountries\Casts\Currency; class MyModel{ // ... protected $casts = [ 'currency' => Currency::class, ]; // ... } // Now you can dynamically retrieve all meta data associated with the currency MyModel::first()->currency; // When filling the model, the ISO code (string) or the model can be used MyModel::first()->update(['currency' => 'USD']); MyModel::first()->update(['currency' => Io238\ISOCountries\Models\Currency::find('USD')]); ``` -------------------------------- ### Retrieve Languages Spoken in a Country (PHP) Source: https://github.com/io238/laravel-iso-countries/blob/main/README.md This snippet demonstrates how to retrieve all languages spoken in a specific country using the Country model and its 'languages' relationship. It requires the 'Country' model to be available. ```php Country::find('LU')->languages; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.