Skip to content

aeq-dev/laravel-world

Repository files navigation

LaravelWorld

Latest Version on Packagist Total Downloads Build Status StyleCI

The Laravel-World is a Laravel package which provides a list of the countries, states, cities, timezones, currencies and languages.

It can be consumed with the World Facade

Installation

Via Composer

    composer require bkfdev/laravel-world

Publish

    php artisan vendor:publish --force --provider="Bkfdev\World\LaravelWorldServiceProvider"

Setup Config

<?php

return [
    /*
	|--------------------------------------------------------------------------
	| Allowed countries to be loaded
	| Leave it empty to load all countries
	|--------------------------------------------------------------------------
	*/
    'allowed_countries' => [],

    /*
	|--------------------------------------------------------------------------
	| Disallowed countries to not be loaded
	| Leave it empty to allow all countries to be loaded
	|--------------------------------------------------------------------------
	*/
    'disallowed_countries' => [],

    /*
	|--------------------------------------------------------------------------
	| Supported locales.
	|--------------------------------------------------------------------------
	*/
    'accepted_locales' => [
        'ar',
        'en',
        /* 'bn',
        'br',
        'de',
        'es',
        'fr',
        'ja',
        'kr',
        'nl',
        'pl',
        'pt',
        'ro',
        'ru',
        'zh', */
    ],
    /*
	|--------------------------------------------------------------------------
	| Enabled modules.
	| The cities module depends on the states module.
	|--------------------------------------------------------------------------
	*/
    'modules' => [
        'states' => true,
        'cities' => true,
        'timezones' => true,
        'currencies' => true,
        'languages' => true,
    ],

    /*
	|--------------------------------------------------------------------------
	| Migrations.
	|--------------------------------------------------------------------------
	*/
    'migrations' => [
        'countries' => [
            'table_name' => 'world_countries',
            'optional_fields' => [

    ...

Migrate

    php artisan migrate

Run Command to import data

    php artisan world:init

Or you may add some countries by running this command :

    php artisan world:add us sa dz

Usage

It's just an eloquent so you may run whetever your want

    use Bkfdev\World\World;
Get All countries :
    $countries = World::Countries();
Get country by code iso2 or iso3 :
    $country = World::getCountryByCode($code);
    return :
    [
        "id" => 1
        "iso2" => "DZ"
        "name" => "Algeria"
        "status" => 1
        "phone_code" => "213"
        "iso3" => "DZA"
        "native" => "الجزائر"
        "region" => "Africa"
        "subregion" => "Northern Africa"
        "latitude" => "28.00000000"
        "longitude" => "3.00000000"
        "emoji" => "🇩🇿"
        "emojiU" => "U+1F1E9 U+1F1FF"
    ]
Get country by name :
    $country = World::getCountryByName($name);
Get states of a give country by code :
    $states = World::getStatesOfCountry($code);

Change log

Please see the changelog for more information on what has changed recently.

Testing

    composer test

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email bkfdev@gmail.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages