https://github.com/antonioribeiro/countries-laravel
Countries for Laravel
https://github.com/antonioribeiro/countries-laravel
Last synced: 6 months ago
JSON representation
Countries for Laravel
- Host: GitHub
- URL: https://github.com/antonioribeiro/countries-laravel
- Owner: antonioribeiro
- License: bsd-3-clause
- Created: 2018-01-22T12:01:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-05-01T07:41:42.000Z (over 2 years ago)
- Last Synced: 2025-03-28T10:06:37.390Z (7 months ago)
- Language: PHP
- Size: 41 KB
- Stars: 148
- Watchers: 7
- Forks: 46
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Countries for Laravel
### What does it gives you?
This package has all sorts of information about countries:
| info | items |
------------------|-------:|
| taxes | 32 |
| geometry maps | 248 |
| topology maps | 248 |
| currencies | 256 |
| countries | 266 |
| timezones | 423 |
| borders | 649 |
| flags | 1,570 |
| states | 4,526 |
| cities | 7,376 |
| timezones times | 81,153 |### Validation
The validation is extending Laravel's validation, so you can use it like any other validation rules, like
```php
/**
* Store a new blog post.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required|unique:posts|max:255',
'body' => 'required',
'country' => 'country' //Checks if valid name.common
]);// The blog post is valid, store in database...
}
```Which validation rules there is and what there name should be, can all be configured in the configuration file.
```php
'validation' => [
'rules' => [
'countryCommon' => 'name.common'
]
]
```By changing the configuration like this, we can now access the property `name.common`, by the validation rule `countryCommon`
You have to define all the validations rules in settings, only a few is defined by default, the default is
```php
'rules' => [
'country' => 'name.common',
'cca2',
'cca3',
'ccn3',
'cioc',
'currencies' => 'ISO4217',
'language',
'language_short' => 'ISO639_3',
]
```### Documentation
This package is a Laravel bridge, please refer to the [main package repository](https://github.com/antonioribeiro/countries) for more information and docs.
## Requirements
- PHP 7.0+
- Laravel 5.5+## Installing
Use Composer to install it:
```
composer require pragmarx/countries-laravel
```## Publishing assets
You can publish configuration by doing:
```
php artisan vendor:publish --provider=PragmaRX\\CountriesLaravel\\Package\\ServiceProvider
```## Usage
After installing you'll have access to the Countries Façade, and the package is based on Laravel Collections, so you basically have access to all methods in Collections, like
```php
$france = Countries::where('name.common', 'France');
```## Flag routes
You can refer directly to an SVG flag by linking
```
/pragmarx/countries/flag/download/.svg
/pragmarx/countries/flag/file/.svg
```Examples:
```
https://laravel.com/pragmarx/countries/flag/download/usa.svg
https://laravel.com/pragmarx/countries/flag/file/usa.svg
```http://pragmarx.test/pragmarx/countries/flag/file/usa.svg
These routes can be turned off in the configuration file:
```php
'routes' => [
'enabled' => false,
]
```## Author
[Antonio Carlos Ribeiro](http://twitter.com/iantonioribeiro)
## License
Countries is licensed under the MIT License - see the `LICENSE` file for details
## Contributing
Pull requests and issues are more than welcome.