Download the PHP package pragmarx/countries without Composer
On this page you can find all versions of the php package pragmarx/countries. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
All versions of countries with dependencies
Informations about the package countries
What does it gives you?
This package has all sorts of information about countries:
Geology and topology maps
Amongst many other information you'll be able to plot country maps:
- PHP 7.0+
Use Composer to install it:
Should both return
Overloading the default configuration:
This package is not tied to Laravel and doesn't require it to be installed (we have a bridge for this purpose), but it has Laravel Collections in its core, all methods in Collections are available, this way you can do things like filter, map, reduce, search, sort, reject, and a lot more. It, actually, uses Coollection, which is Laravel Collections with a fluent syntax, allowing us to have access to array keys (and values) as object properties.
To get all countries in the data base you just have to:
To get a json you:
Filter by keys and values:
Will find Brazil by its common name, which is a
Or alternatively you can filter like this
And, you can go deepeer
Or search by the country top level domain
And use things like pluck
The package uses a modified Collection which allows you to access properties and methods as objects:
Borders hydration is disabled by default, but you can have your borders hydrated easily by calling the hydrate method:
To improve performance, hydration, which is enabled by default, can be disable on most country properties, and this is how you manually hydrate properties:
Those are some of the hydratable properties:
Extra where rules
Some properties are stored differently and we therefore need special rules for accessing them, these properties are
ISO639_3=> The 3 letter language code.
ISO4217=> The 3 letter currency code.
You can of course access them like other properties
Sometimes you would like to access a property by a different name, this can be done in settings, this way
Here we bind the language 3 letter short code ISO format to
lca3, which is short for
language code alpha 3-letter.
So now we can access the property by
Some other examples from Laravel News and some other contributors
Generate a list of all countries with code, using native name and common
Should give you 267 (or so) countries like:
Generate a list of countries
Generate a list of currencies
Get the currency symbol
Generate a list of States
Hydrate and get a cities
Get a countries currencies
Get all currencies
Get the timezone for a State
Get all timezones for a country
Get all times for a timezone
Countries provides many different flag sources, including SVG flags. This is how you use one of the available sources:
Import it to your project
Use Countries to get the flag span
Render it in your blade template
You can publish configuration by doing:
This package uses some other open source packages and, until we don't build a better documentation, you can find some more info about data on mledoze/countries and how to use it on this fantastic Laravel News article.
Please check the copyright section for a complete list of packages used by this one.
No data files (JSON, images, icons...) on this project can be updated manually. We will close all pull requests requiring manual updates to those files will be closed, because the update script will delete them anyway.
If you find something wrong with data, you, please, have to ask the package managers (listed data sources and on the copyright section) to fix them, and then you can yourself run the update script to properly update them on this repository.
This package comes with the
update.php script, which you MUST use to update the data files. It will download all info from all packages and automatically build the
.json (and some others like
.svg too). This is how you do it:
And wait for a *very long time** (sometimes it looks like stuck but it's not) until it finishes rebuilding everything, then it's just a matter of staging, commit, push all regenerated files, and draft a new PR.
Since this data is not supposed to change, calls are automatically cached.
If you want to change this behaviour, you can edit
config/countries.php file once it's published.
- sample-partial.json: example of a country with no borders hydrated.
- sample-full.json: example of a fully hydrated country.
To build the countries database and relations, this package make use of those sources and packages:
- Natural Earth Vector
Countries is licensed under the BSD 3-Clause License - see the
LICENSE file for details
Pull requests and issues are more than welcome.