placecodex / laravel-countries
A list of all countries, optimized for Laravel 8
Requires
- php: ^7.3|^8.0
- astrotomic/laravel-translatable: ^11.8
- laravel/framework: ^8.12
Requires (Dev)
- doctrine/dbal: ^3.0
- laravel/legacy-factories: ^1.0.4
- orchestra/testbench: ~3.6.7 || ~3.7.8 || ~3.8.6 || ^4.8 || ^5.2 || ^6.0
- phpunit/phpunit: ^8.0
This package is not auto-updated.
Last update: 2025-01-28 01:21:16 UTC
README
Very short description
Laravel-Countries, is a package that contains everything you need to start a new project and have all countries, information and translations on hand. And all this optimized for Laravel 8.
The package provides all data directly to your database, allowing you to link to any other table in your database, in a simple and usual way.
Geology and topology maps
Amongst many other information you'll be able to plot country maps:
Available Languages?
Requirements
-
PHP >= ^7.3 | ^8.0
-
laravel/framework >= ^8.12
-
dimsav/laravel-translatable >= ^11.8
Installation
You can install the package via composer:
composer require lwwcas/laravel-countries composer dump-autoload
- Put this line into database\seeds\DatabaseSeeder.php in run function
$this->call(\Lwwcas\LaravelCountries\Database\Seeders\LcDatabaseSeeder::class);
- Run migrations
php artisan migrate
- Run seeds or only the LcDatabaseSeeder class
php artisan db:seed
Usage
You can access all the information in the database with a simple query
use Lwwcas\LaravelCountries\Models\Country; Country::whereIso('BR')->first(); Country::whereIsoAlpha3('BRA')->first(); Country::whereSlug('brasil')->first();
How to integrate into my project?
In your table you can simply add the foreign key.
Only this will allow you to make a relationship with the country table
$table->integer('lc_country_id')->unsigned();
Being optional, but strongly recommended, you should use the Foreign Key Constraints that Laravel provides.
$table->foreign('lc_country_id')->references('id')->on('lc_countries');
Example of implementation in the users table
To make a relationship with the regions table
$table->tinyInteger('lc_region_id')->unsigned(); $table->foreign('lc_region_id')->references('id')->on('lc_regions');
Take a good look at the Model and see the package makes it easy
Example data
{ "id": 30, "lc_region_id": 2, "uuid": "343d2082-f6fb-42e6-ac7a-f78dad39de31", "slug": "brazil", "name": "Brazil", "official_name": "Federative Republic of Brazil", "iso_alpha_2": "BR", "iso_alpha_3": "BRA", "iso_numeric": 76, "geoname_id": "3469034", "international_phone": "55", "languages": "[pt]", "tld": "[.br]", "wmo": "BZ", "emoji": { "img": "🇧🇷", "uCode": "U+1F1E7 U+1F1F7" }, "color_hex": [ "#008000", "#ffff00" ], "color_rgb": [ "0,128,0", "255,255,0" ], "coordinates": { "latitude": { "classic": "10 00 S", "desc": "-10.81045150756836" }, "longitude": { "classic": "55 00 W", "desc": "-52.97311782836914" } }, "coordinates_limit": { "latitude": { "max": "5.266667", "min": "-33.733333" }, "longitude": { "max": "-28.85", "min": "-73.75" } }, "visible": true, "translations": [ { "id": 30, "lc_country_id": 30, "name": "Brazil", "slug": "brazil", "locale": "en" } ] }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email lwwcas@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.