├── .github └── FUNDING.yml ├── .styleci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── config.php └── src ├── Console └── Commands │ └── InstallCountryDataPackage.php ├── LaravelCountryStateCityDataServiceProvider.php └── resources └── stubs ├── DataProviders ├── CityDataProvider.stub ├── CountryDataProvider.stub └── StateDataProvider.stub ├── Models ├── City.stub ├── Country.stub └── State.stub ├── migrations └── 2014_02_04_000000_create_country_state_city_table.stub └── seeders └── CountryStateCityTableSeeder.stub /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [dipeshsukhia] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-country-state-city-data` will be documented in this file 4 | 5 | ## 2.0.0 - 2021-05-12 6 | 7 | - "Integrity constraint violation: 1062 Duplicate entry" Issue fixed 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Dipesh Sukhia 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel country-state-city-data 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/dipeshsukhia/laravel-country-state-city-data.svg?style=flat-square)](https://packagist.org/packages/dipeshsukhia/laravel-country-state-city-data) 4 | [![Total Downloads](https://img.shields.io/packagist/dt/dipeshsukhia/laravel-country-state-city-data.svg?style=flat-square)](https://packagist.org/packages/dipeshsukhia/laravel-country-state-city-data) 5 | 6 | World`s Country State City Provider for Laravel 7 | 8 | ## Installation 9 | 10 | You can install the package via composer: 11 | 12 | ```bash 13 | composer require dipeshsukhia/laravel-country-state-city-data --dev 14 | ``` 15 | 16 | ## Usage 17 | 18 | ``` php 19 | php artisan country-data:install 20 | ``` 21 | 22 | ### Requirements 23 | 24 | ``` bash 25 | Laravel 5.8.x, 6.x, 7.x, 8.x, 9.x, 10.x, 11.x 26 | PHP >= 7.1.3 or Grater 27 | ``` 28 | 29 | ## Contributing 30 | 31 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 32 | 33 | ### Security 34 | 35 | If you discover any security related issues, please email dipesh.sukhia@gmail.com instead of using the issue tracker. 36 | 37 | ## Credits 38 | 39 | - [Dipesh Sukhia](https://github.com/dipeshsukhia) 40 | - [Bhavin Gajjar](https://github.com/bhavingajjar) 41 | - [All Contributors](../../contributors) 42 | 43 | ## License 44 | 45 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 46 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dipeshsukhia/laravel-country-state-city-data", 3 | "description": "Country State City Data Provider", 4 | "keywords": [ 5 | "dipeshsukhia", 6 | "laravel-country-state-city-data", 7 | "countries", 8 | "country", 9 | "laravel", 10 | "state", 11 | "states", 12 | "city", 13 | "cities" 14 | ], 15 | "homepage": "https://github.com/dipeshsukhia/laravel-country-state-city-data", 16 | "license": "MIT", 17 | "type": "library", 18 | "authors": [ 19 | { 20 | "name": "Dipesh Sukhia", 21 | "email": "dipesh.sukhia@gmail.com", 22 | "role": "Developer" 23 | }, 24 | { 25 | "name": "Bhavin Gajjar", 26 | "email": "gajjarbhavin22@gmail.com", 27 | "role": "Developer" 28 | } 29 | ], 30 | "require": { 31 | "php": ">=7.1.3", 32 | "illuminate/support": "^5.8|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0" 33 | }, 34 | "require-dev": { 35 | "phpunit/phpunit": "^9.0|^10.5" 36 | }, 37 | "autoload": { 38 | "psr-4": { 39 | "DipeshSukhia\\LaravelCountryStateCityData\\": "src" 40 | } 41 | }, 42 | "autoload-dev": { 43 | "psr-4": { 44 | "DipeshSukhia\\LaravelCountryStateCityData\\Tests\\": "tests" 45 | } 46 | }, 47 | "scripts": { 48 | "test": "vendor/bin/phpunit", 49 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 50 | }, 51 | "minimum-stability": "stable", 52 | "extra": { 53 | "laravel": { 54 | "providers": [ 55 | "DipeshSukhia\\LaravelCountryStateCityData\\LaravelCountryStateCityDataServiceProvider" 56 | ] 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | info('Installing Country Data...'); 42 | 43 | $this->info('Publishing Configuration...'); 44 | $this->publishConfiguration(false); 45 | 46 | $this->call('migrate', [ 47 | '--path' => 'database/migrations/2014_02_04_000000_create_country_state_city_table.php' 48 | ]); 49 | 50 | $this->call('db:seed', [ 51 | '--class' => CountryStateCityTableSeeder::class 52 | ]); 53 | 54 | $this->info('Installed Country Data'); 55 | return true; 56 | } 57 | 58 | private function publishConfiguration($forcePublish = false) 59 | { 60 | $params = [ 61 | '--provider' => "DipeshSukhia\LaravelCountryStateCityData\LaravelCountryStateCityDataServiceProvider", 62 | '--tag' => "LaravelCountryStateCityData" 63 | ]; 64 | if ($forcePublish === true) { 65 | $params['--force'] = ''; 66 | } 67 | $this->call('vendor:publish', $params); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/LaravelCountryStateCityDataServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 19 | 20 | /* model */ 21 | if (is_dir(base_path('app/Models'))) { 22 | $modelDir = base_path('app/Models'); 23 | $modelNameSpace = "\\Models"; 24 | } else { 25 | $modelDir = base_path('app'); 26 | $modelNameSpace = ""; 27 | } 28 | 29 | foreach (['Country', 'State', 'City'] as $modelName) { 30 | $ModelTemplate = $this->getStubContents( "Models/" . $modelName . ".stub"); 31 | $ModelTemplate = str_replace('{{modelNameSpace}}', $modelNameSpace, $ModelTemplate); 32 | file_put_contents($modelDir . "/" . $modelName . ".php", $ModelTemplate); 33 | } 34 | /* model */ 35 | 36 | /* seeders */ 37 | if (is_dir(database_path('seeds'))) { 38 | $seedDir = database_path('seeds'); 39 | $seederNameSpace = ""; 40 | } else { 41 | $seedDir = database_path('seeders'); 42 | $seederNameSpace = "namespace Database\\Seeders;\n"; 43 | } 44 | $seederTemplate = $this->getStubContents('seeders/CountryStateCityTableSeeder.stub'); 45 | $seederTemplate = str_replace('{{seederNameSpace}}', $seederNameSpace, $seederTemplate); 46 | $seederTemplate = str_replace('{{modelNameSpace}}', $modelNameSpace, $seederTemplate); 47 | file_put_contents($seedDir . '/CountryStateCityTableSeeder.php', $seederTemplate); 48 | /* seeders */ 49 | 50 | /* stubs */ 51 | $this->publishes([ 52 | __DIR__ . '/resources/stubs/migrations/2014_02_04_000000_create_country_state_city_table.stub' => database_path('migrations/2014_02_04_000000_create_country_state_city_table.php'), 53 | __DIR__ . '/resources/stubs/DataProviders/CountryDataProvider.stub' => app_path('DataProviders/CountryDataProvider.php'), 54 | __DIR__ . '/resources/stubs/DataProviders/StateDataProvider.stub' => app_path('DataProviders/StateDataProvider.php'), 55 | __DIR__ . '/resources/stubs/DataProviders/CityDataProvider.stub' => app_path('DataProviders/CityDataProvider.php'), 56 | ], 'LaravelCountryStateCityData'); 57 | /* stubs */ 58 | 59 | // Registering package commands. 60 | $this->commands([ 61 | InstallCountryDataPackage::class, 62 | ]); 63 | } 64 | } 65 | 66 | /** 67 | * Register the application services. 68 | */ 69 | public function register() 70 | { 71 | // 72 | } 73 | 74 | private function getStubContents( string $stubName ) 75 | { 76 | return file_get_contents(self::STUB_DIR . $stubName); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/resources/stubs/DataProviders/CountryDataProvider.stub: -------------------------------------------------------------------------------- 1 | '1', 'name' => 'afghanistan'], 11 | ['id' => '2', 'name' => 'albania'], 12 | ['id' => '3', 'name' => 'algeria'], 13 | ['id' => '4', 'name' => 'american samoa'], 14 | ['id' => '5', 'name' => 'andorra'], 15 | ['id' => '6', 'name' => 'angola'], 16 | ['id' => '7', 'name' => 'anguilla'], 17 | ['id' => '8', 'name' => 'antarctica'], 18 | ['id' => '9', 'name' => 'antigua and barbuda'], 19 | ['id' => '10', 'name' => 'argentina'], 20 | ['id' => '11', 'name' => 'armenia'], 21 | ['id' => '12', 'name' => 'aruba'], 22 | ['id' => '13', 'name' => 'australia'], 23 | ['id' => '14', 'name' => 'austria'], 24 | ['id' => '15', 'name' => 'azerbaijan'], 25 | ['id' => '16', 'name' => 'bahamas the'], 26 | ['id' => '17', 'name' => 'bahrain'], 27 | ['id' => '18', 'name' => 'bangladesh'], 28 | ['id' => '19', 'name' => 'barbados'], 29 | ['id' => '20', 'name' => 'belarus'], 30 | ['id' => '21', 'name' => 'belgium'], 31 | ['id' => '22', 'name' => 'belize'], 32 | ['id' => '23', 'name' => 'benin'], 33 | ['id' => '24', 'name' => 'bermuda'], 34 | ['id' => '25', 'name' => 'bhutan'], 35 | ['id' => '26', 'name' => 'bolivia'], 36 | ['id' => '27', 'name' => 'bosnia and herzegovina'], 37 | ['id' => '28', 'name' => 'botswana'], 38 | ['id' => '29', 'name' => 'bouvet island'], 39 | ['id' => '30', 'name' => 'brazil'], 40 | ['id' => '31', 'name' => 'british indian ocean territory'], 41 | ['id' => '32', 'name' => 'brunei'], 42 | ['id' => '33', 'name' => 'bulgaria'], 43 | ['id' => '34', 'name' => 'burkina faso'], 44 | ['id' => '35', 'name' => 'burundi'], 45 | ['id' => '36', 'name' => 'cambodia'], 46 | ['id' => '37', 'name' => 'cameroon'], 47 | ['id' => '38', 'name' => 'canada'], 48 | ['id' => '39', 'name' => 'cape verde'], 49 | ['id' => '40', 'name' => 'cayman islands'], 50 | ['id' => '41', 'name' => 'central african republic'], 51 | ['id' => '42', 'name' => 'chad'], 52 | ['id' => '43', 'name' => 'chile'], 53 | ['id' => '44', 'name' => 'china'], 54 | ['id' => '45', 'name' => 'christmas island'], 55 | ['id' => '46', 'name' => 'cocos (keeling) islands'], 56 | ['id' => '47', 'name' => 'colombia'], 57 | ['id' => '48', 'name' => 'comoros'], 58 | ['id' => '49', 'name' => 'congo'], 59 | ['id' => '50', 'name' => 'congo the democratic republic of the'], 60 | ['id' => '51', 'name' => 'cook islands'], 61 | ['id' => '52', 'name' => 'costa rica'], 62 | ['id' => '53', 'name' => 'cote d\'ivoire (ivory coast)'], 63 | ['id' => '54', 'name' => 'croatia (hrvatska)'], 64 | ['id' => '55', 'name' => 'cuba'], 65 | ['id' => '56', 'name' => 'cyprus'], 66 | ['id' => '57', 'name' => 'czech republic'], 67 | ['id' => '58', 'name' => 'denmark'], 68 | ['id' => '59', 'name' => 'djibouti'], 69 | ['id' => '60', 'name' => 'dominica'], 70 | ['id' => '61', 'name' => 'dominican republic'], 71 | ['id' => '62', 'name' => 'east timor'], 72 | ['id' => '63', 'name' => 'ecuador'], 73 | ['id' => '64', 'name' => 'egypt'], 74 | ['id' => '65', 'name' => 'el salvador'], 75 | ['id' => '66', 'name' => 'equatorial guinea'], 76 | ['id' => '67', 'name' => 'eritrea'], 77 | ['id' => '68', 'name' => 'estonia'], 78 | ['id' => '69', 'name' => 'ethiopia'], 79 | ['id' => '70', 'name' => 'external territories of australia'], 80 | ['id' => '71', 'name' => 'falkland islands'], 81 | ['id' => '72', 'name' => 'faroe islands'], 82 | ['id' => '73', 'name' => 'fiji islands'], 83 | ['id' => '74', 'name' => 'finland'], 84 | ['id' => '75', 'name' => 'france'], 85 | ['id' => '76', 'name' => 'french guiana'], 86 | ['id' => '77', 'name' => 'french polynesia'], 87 | ['id' => '78', 'name' => 'french southern territories'], 88 | ['id' => '79', 'name' => 'gabon'], 89 | ['id' => '80', 'name' => 'gambia the'], 90 | ['id' => '81', 'name' => 'georgia'], 91 | ['id' => '82', 'name' => 'germany'], 92 | ['id' => '83', 'name' => 'ghana'], 93 | ['id' => '84', 'name' => 'gibraltar'], 94 | ['id' => '85', 'name' => 'greece'], 95 | ['id' => '86', 'name' => 'greenland'], 96 | ['id' => '87', 'name' => 'grenada'], 97 | ['id' => '88', 'name' => 'guadeloupe'], 98 | ['id' => '89', 'name' => 'guam'], 99 | ['id' => '90', 'name' => 'guatemala'], 100 | ['id' => '91', 'name' => 'guernsey and alderney'], 101 | ['id' => '92', 'name' => 'guinea'], 102 | ['id' => '93', 'name' => 'guinea-bissau'], 103 | ['id' => '94', 'name' => 'guyana'], 104 | ['id' => '95', 'name' => 'haiti'], 105 | ['id' => '96', 'name' => 'heard and mcdonald islands'], 106 | ['id' => '97', 'name' => 'honduras'], 107 | ['id' => '98', 'name' => 'hong kong s.a.r.'], 108 | ['id' => '99', 'name' => 'hungary'], 109 | ['id' => '100', 'name' => 'iceland'], 110 | ['id' => '101', 'name' => 'india'], 111 | ['id' => '102', 'name' => 'indonesia'], 112 | ['id' => '103', 'name' => 'iran'], 113 | ['id' => '104', 'name' => 'iraq'], 114 | ['id' => '105', 'name' => 'ireland'], 115 | ['id' => '106', 'name' => 'israel'], 116 | ['id' => '107', 'name' => 'italy'], 117 | ['id' => '108', 'name' => 'jamaica'], 118 | ['id' => '109', 'name' => 'japan'], 119 | ['id' => '110', 'name' => 'jersey'], 120 | ['id' => '111', 'name' => 'jordan'], 121 | ['id' => '112', 'name' => 'kazakhstan'], 122 | ['id' => '113', 'name' => 'kenya'], 123 | ['id' => '114', 'name' => 'kiribati'], 124 | ['id' => '115', 'name' => 'korea north'], 125 | ['id' => '116', 'name' => 'korea south'], 126 | ['id' => '117', 'name' => 'kuwait'], 127 | ['id' => '118', 'name' => 'kyrgyzstan'], 128 | ['id' => '119', 'name' => 'laos'], 129 | ['id' => '120', 'name' => 'latvia'], 130 | ['id' => '121', 'name' => 'lebanon'], 131 | ['id' => '122', 'name' => 'lesotho'], 132 | ['id' => '123', 'name' => 'liberia'], 133 | ['id' => '124', 'name' => 'libya'], 134 | ['id' => '125', 'name' => 'liechtenstein'], 135 | ['id' => '126', 'name' => 'lithuania'], 136 | ['id' => '127', 'name' => 'luxembourg'], 137 | ['id' => '128', 'name' => 'macau s.a.r.'], 138 | ['id' => '129', 'name' => 'macedonia'], 139 | ['id' => '130', 'name' => 'madagascar'], 140 | ['id' => '131', 'name' => 'malawi'], 141 | ['id' => '132', 'name' => 'malaysia'], 142 | ['id' => '133', 'name' => 'maldives'], 143 | ['id' => '134', 'name' => 'mali'], 144 | ['id' => '135', 'name' => 'malta'], 145 | ['id' => '136', 'name' => 'man (isle of)'], 146 | ['id' => '137', 'name' => 'marshall islands'], 147 | ['id' => '138', 'name' => 'martinique'], 148 | ['id' => '139', 'name' => 'mauritania'], 149 | ['id' => '140', 'name' => 'mauritius'], 150 | ['id' => '141', 'name' => 'mayotte'], 151 | ['id' => '142', 'name' => 'mexico'], 152 | ['id' => '143', 'name' => 'micronesia'], 153 | ['id' => '144', 'name' => 'moldova'], 154 | ['id' => '145', 'name' => 'monaco'], 155 | ['id' => '146', 'name' => 'mongolia'], 156 | ['id' => '147', 'name' => 'montserrat'], 157 | ['id' => '148', 'name' => 'morocco'], 158 | ['id' => '149', 'name' => 'mozambique'], 159 | ['id' => '150', 'name' => 'myanmar'], 160 | ['id' => '151', 'name' => 'namibia'], 161 | ['id' => '152', 'name' => 'nauru'], 162 | ['id' => '153', 'name' => 'nepal'], 163 | ['id' => '154', 'name' => 'netherlands antilles'], 164 | ['id' => '155', 'name' => 'netherlands the'], 165 | ['id' => '156', 'name' => 'new caledonia'], 166 | ['id' => '157', 'name' => 'new zealand'], 167 | ['id' => '158', 'name' => 'nicaragua'], 168 | ['id' => '159', 'name' => 'niger'], 169 | ['id' => '160', 'name' => 'nigeria'], 170 | ['id' => '161', 'name' => 'niue'], 171 | ['id' => '162', 'name' => 'norfolk island'], 172 | ['id' => '163', 'name' => 'northern mariana islands'], 173 | ['id' => '164', 'name' => 'norway'], 174 | ['id' => '165', 'name' => 'oman'], 175 | ['id' => '166', 'name' => 'pakistan'], 176 | ['id' => '167', 'name' => 'palau'], 177 | ['id' => '168', 'name' => 'palestinian territory occupied'], 178 | ['id' => '169', 'name' => 'panama'], 179 | ['id' => '170', 'name' => 'papua new guinea'], 180 | ['id' => '171', 'name' => 'paraguay'], 181 | ['id' => '172', 'name' => 'peru'], 182 | ['id' => '173', 'name' => 'philippines'], 183 | ['id' => '174', 'name' => 'pitcairn island'], 184 | ['id' => '175', 'name' => 'poland'], 185 | ['id' => '176', 'name' => 'portugal'], 186 | ['id' => '177', 'name' => 'puerto rico'], 187 | ['id' => '178', 'name' => 'qatar'], 188 | ['id' => '179', 'name' => 'reunion'], 189 | ['id' => '180', 'name' => 'romania'], 190 | ['id' => '181', 'name' => 'russia'], 191 | ['id' => '182', 'name' => 'rwanda'], 192 | ['id' => '183', 'name' => 'saint helena'], 193 | ['id' => '184', 'name' => 'saint kitts and nevis'], 194 | ['id' => '185', 'name' => 'saint lucia'], 195 | ['id' => '186', 'name' => 'saint pierre and miquelon'], 196 | ['id' => '187', 'name' => 'saint vincent and the grenadines'], 197 | ['id' => '188', 'name' => 'samoa'], 198 | ['id' => '189', 'name' => 'san marino'], 199 | ['id' => '190', 'name' => 'sao tome and principe'], 200 | ['id' => '191', 'name' => 'saudi arabia'], 201 | ['id' => '192', 'name' => 'senegal'], 202 | ['id' => '193', 'name' => 'serbia'], 203 | ['id' => '194', 'name' => 'seychelles'], 204 | ['id' => '195', 'name' => 'sierra leone'], 205 | ['id' => '196', 'name' => 'singapore'], 206 | ['id' => '197', 'name' => 'slovakia'], 207 | ['id' => '198', 'name' => 'slovenia'], 208 | ['id' => '199', 'name' => 'smaller territories of the uk'], 209 | ['id' => '200', 'name' => 'solomon islands'], 210 | ['id' => '201', 'name' => 'somalia'], 211 | ['id' => '202', 'name' => 'south africa'], 212 | ['id' => '203', 'name' => 'south georgia'], 213 | ['id' => '204', 'name' => 'south sudan'], 214 | ['id' => '205', 'name' => 'spain'], 215 | ['id' => '206', 'name' => 'sri lanka'], 216 | ['id' => '207', 'name' => 'sudan'], 217 | ['id' => '208', 'name' => 'suriname'], 218 | ['id' => '209', 'name' => 'svalbard and jan mayen islands'], 219 | ['id' => '210', 'name' => 'swaziland'], 220 | ['id' => '211', 'name' => 'sweden'], 221 | ['id' => '212', 'name' => 'switzerland'], 222 | ['id' => '213', 'name' => 'syria'], 223 | ['id' => '214', 'name' => 'taiwan'], 224 | ['id' => '215', 'name' => 'tajikistan'], 225 | ['id' => '216', 'name' => 'tanzania'], 226 | ['id' => '217', 'name' => 'thailand'], 227 | ['id' => '218', 'name' => 'togo'], 228 | ['id' => '219', 'name' => 'tokelau'], 229 | ['id' => '220', 'name' => 'tonga'], 230 | ['id' => '221', 'name' => 'trinidad and tobago'], 231 | ['id' => '222', 'name' => 'tunisia'], 232 | ['id' => '223', 'name' => 'turkey'], 233 | ['id' => '224', 'name' => 'turkmenistan'], 234 | ['id' => '225', 'name' => 'turks and caicos islands'], 235 | ['id' => '226', 'name' => 'tuvalu'], 236 | ['id' => '227', 'name' => 'uganda'], 237 | ['id' => '228', 'name' => 'ukraine'], 238 | ['id' => '229', 'name' => 'united arab emirates'], 239 | ['id' => '230', 'name' => 'united kingdom'], 240 | ['id' => '231', 'name' => 'united states'], 241 | ['id' => '232', 'name' => 'united states minor outlying islands'], 242 | ['id' => '233', 'name' => 'uruguay'], 243 | ['id' => '234', 'name' => 'uzbekistan'], 244 | ['id' => '235', 'name' => 'vanuatu'], 245 | ['id' => '236', 'name' => 'vatican city state (holy see)'], 246 | ['id' => '237', 'name' => 'venezuela'], 247 | ['id' => '238', 'name' => 'vietnam'], 248 | ['id' => '239', 'name' => 'virgin islands (british)'], 249 | ['id' => '240', 'name' => 'virgin islands (us)'], 250 | ['id' => '241', 'name' => 'wallis and futuna islands'], 251 | ['id' => '242', 'name' => 'western sahara'], 252 | ['id' => '243', 'name' => 'yemen'], 253 | ['id' => '244', 'name' => 'yugoslavia'], 254 | ['id' => '245', 'name' => 'zambia'], 255 | ['id' => '246', 'name' => 'zimbabwe'] 256 | ]; 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /src/resources/stubs/Models/City.stub: -------------------------------------------------------------------------------- 1 | belongsTo(State::class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/resources/stubs/Models/Country.stub: -------------------------------------------------------------------------------- 1 | hasMany(State::class); 21 | } 22 | 23 | public function cities(): HasManyThrough 24 | { 25 | return $this->hasManyThrough(City::class, State::class); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/resources/stubs/Models/State.stub: -------------------------------------------------------------------------------- 1 | hasMany(City::class); 21 | } 22 | 23 | public function country(): BelongsTo 24 | { 25 | return $this->belongsTo(Country::class); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/resources/stubs/migrations/2014_02_04_000000_create_country_state_city_table.stub: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 19 | $table->string('name',255); 20 | $table->enum('status', ['active', 'inactive'])->default('active'); 21 | $table->timestamp('created_at')->useCurrent(); 22 | $table->timestamp('updated_at')->useCurrent(); 23 | $table->softDeletes(); 24 | }); 25 | 26 | Schema::create('states', function (Blueprint $table) { 27 | $table->bigIncrements('id'); 28 | $table->unsignedBigInteger('country_id'); 29 | $table->string('name',255); 30 | $table->enum('status', ['active', 'inactive'])->default('active'); 31 | $table->timestamp('created_at')->useCurrent(); 32 | $table->timestamp('updated_at')->useCurrent(); 33 | $table->softDeletes(); 34 | 35 | $table->foreign('country_id')->references('id')->on('countries') 36 | ->onUpdate('cascade')->onDelete('cascade'); 37 | }); 38 | 39 | Schema::create('cities', function (Blueprint $table) { 40 | $table->bigIncrements('id'); 41 | $table->unsignedBigInteger('state_id'); 42 | $table->string('name',255); 43 | $table->enum('status', ['active', 'inactive'])->default('active'); 44 | $table->timestamp('created_at')->useCurrent(); 45 | $table->timestamp('updated_at')->useCurrent(); 46 | $table->softDeletes(); 47 | 48 | $table->foreign('state_id')->references('id')->on('states') 49 | ->onUpdate('cascade')->onDelete('cascade'); 50 | }); 51 | } 52 | 53 | /** 54 | * Reverse the migrations. 55 | * 56 | * @return void 57 | */ 58 | public function down() 59 | { 60 | Schema::dropIfExists('cities'); 61 | Schema::dropIfExists('states'); 62 | Schema::dropIfExists('countries'); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/resources/stubs/seeders/CountryStateCityTableSeeder.stub: -------------------------------------------------------------------------------- 1 | chunk(15000) as $chunkCities) { 23 | City::insertOrIgnore($chunkCities->toArray()); 24 | } 25 | } 26 | } 27 | --------------------------------------------------------------------------------