├── .editorconfig ├── database ├── migrations │ ├── 2016_02_05_000000_create_states_table.php │ └── 2016_02_05_000001_create_cities_table.php └── seeds │ └── StatesTableSeeder.php ├── app └── Models │ ├── State.php │ └── City.php ├── LICENSE └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_style = space 7 | indent_size = 4 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /database/migrations/2016_02_05_000000_create_states_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 20 | $table->string('name', 64)->unique(); 21 | $table->string('abbr', 2)->unique(); 22 | $table->timestamps(); 23 | $table->softDeletes(); 24 | 25 | }); 26 | 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | 37 | Schema::drop('states'); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /database/migrations/2016_02_05_000001_create_cities_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 20 | $table->integer('state_id')->unsigned(); 21 | $table->foreign('state_id')->references('id')->on('states'); 22 | $table->string('name', 64); 23 | $table->timestamps(); 24 | $table->softDeletes(); 25 | 26 | }); 27 | 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | 38 | Schema::drop('cities'); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/Models/State.php: -------------------------------------------------------------------------------- 1 | hasMany(City::class); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2014-2018 Magno Fernando Brixner Biét 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. 22 | -------------------------------------------------------------------------------- /app/Models/City.php: -------------------------------------------------------------------------------- 1 | 'integer', 38 | ]; 39 | 40 | /** 41 | * The attributes that should be mutated to dates. 42 | * 43 | * @var array 44 | */ 45 | protected $dates = [ 46 | 'deleted_at' 47 | ]; 48 | 49 | /** 50 | * Get the state that owns the city. 51 | */ 52 | public function state() 53 | { 54 | 55 | return $this->belongsTo(State::class, 'state_id'); 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Estados e Cidades do Brasil (Laravel) 2 | 3 | Esta base foi criada com informações do [Instituto Brasileiro de Geografia e Estatística](https://cidades.ibge.gov.br/). Ao todo são **5570 cidades** nos **27 estados** brasileiros. 4 | 5 | ## Como usar? 6 | 7 | ### 1. Baixe 8 | 9 | Baixe e copie as _migrations_ e _seeds_ para as respectivas pastas. 10 | 11 | - `database/seeds/` 12 | - `database/migrations` 13 | 14 | ### 2. Registre os seeds 15 | 16 | No arquivo `DatabaseSeeder.php`, adicione a chamada dos seeds. 17 | 18 | ```php 19 | public function run() { 20 | // ...omitido por brevidade 21 | $this->call([StatesTableSeeder::class, CitiesTableSeeder::class]); 22 | } 23 | ``` 24 | 25 | ### 3. Execute 26 | 27 | Execute `php artisan migrate` e em seguida `php artisan db:seed` ou simplesmente `php artisan migrate --seed`. 28 | 29 | ## Outros formatos disponíveis 30 | 31 | - [CSV](https://github.com/magnobiet/states-cities-brazil/tree/master/CSV) 32 | - [HTML](https://github.com/magnobiet/states-cities-brazil/tree/master/HTML) 33 | - [JSON](https://github.com/magnobiet/states-cities-brazil/tree/master/JSON) 34 | - [PHP](https://github.com/magnobiet/states-cities-brazil/tree/master/PHP) 35 | - [SQL](https://github.com/magnobiet/states-cities-brazil/tree/master/SQL) 36 | 37 | ## Links úteis 38 | 39 | - Portal Cidades do IBGE (https://cidades.ibge.gov.br/) 40 | - API de localidades do IBGE (https://servicodados.ibge.gov.br/api/docs/localidades) 41 | 42 | ## Última atualização de dados 43 | 44 | 05/02/2016 45 | 46 | ## Licença 47 | 48 | Este projeto está licenciado sob a licença [MIT](http://magno.mit-license.org/2014). Copyright © Magno Biét 49 | -------------------------------------------------------------------------------- /database/seeds/StatesTableSeeder.php: -------------------------------------------------------------------------------- 1 | insert([ 23 | [ 24 | "id" => 11, 25 | "name" => "Rondônia", 26 | "abbr" => "RO", 27 | "created_at" => $now, 28 | "updated_at" => $now, 29 | ], [ 30 | "id" => 12, 31 | "name" => "Acre", 32 | "abbr" => "AC", 33 | "created_at" => $now, 34 | "updated_at" => $now, 35 | ], [ 36 | "id" => 13, 37 | "name" => "Amazonas", 38 | "abbr" => "AM", 39 | "created_at" => $now, 40 | "updated_at" => $now, 41 | ], [ 42 | "id" => 14, 43 | "name" => "Roraima", 44 | "abbr" => "RR", 45 | "created_at" => $now, 46 | "updated_at" => $now, 47 | ], [ 48 | "id" => 15, 49 | "name" => "Pará", 50 | "abbr" => "PA", 51 | "created_at" => $now, 52 | "updated_at" => $now, 53 | ], [ 54 | "id" => 16, 55 | "name" => "Amapá", 56 | "abbr" => "AP", 57 | "created_at" => $now, 58 | "updated_at" => $now, 59 | ], [ 60 | "id" => 17, 61 | "name" => "Tocantins", 62 | "abbr" => "TO", 63 | "created_at" => $now, 64 | "updated_at" => $now, 65 | ], [ 66 | "id" => 21, 67 | "name" => "Maranhão", 68 | "abbr" => "MA", 69 | "created_at" => $now, 70 | "updated_at" => $now, 71 | ], [ 72 | "id" => 22, 73 | "name" => "Piauí", 74 | "abbr" => "PI", 75 | "created_at" => $now, 76 | "updated_at" => $now, 77 | ], [ 78 | "id" => 23, 79 | "name" => "Ceará", 80 | "abbr" => "CE", 81 | "created_at" => $now, 82 | "updated_at" => $now, 83 | ], [ 84 | "id" => 24, 85 | "name" => "Rio Grande do Norte", 86 | "abbr" => "RN", 87 | "created_at" => $now, 88 | "updated_at" => $now, 89 | ], [ 90 | "id" => 25, 91 | "name" => "Paraíba", 92 | "abbr" => "PB", 93 | "created_at" => $now, 94 | "updated_at" => $now, 95 | ], [ 96 | "id" => 26, 97 | "name" => "Pernambuco", 98 | "abbr" => "PE", 99 | "created_at" => $now, 100 | "updated_at" => $now, 101 | ], [ 102 | "id" => 27, 103 | "name" => "Alagoas", 104 | "abbr" => "AL", 105 | "created_at" => $now, 106 | "updated_at" => $now, 107 | ], [ 108 | "id" => 28, 109 | "name" => "Sergipe", 110 | "abbr" => "SE", 111 | "created_at" => $now, 112 | "updated_at" => $now, 113 | ], [ 114 | "id" => 29, 115 | "name" => "Bahia", 116 | "abbr" => "BA", 117 | "created_at" => $now, 118 | "updated_at" => $now, 119 | ], [ 120 | "id" => 31, 121 | "name" => "Minas Gerais", 122 | "abbr" => "MG", 123 | "created_at" => $now, 124 | "updated_at" => $now, 125 | ], [ 126 | "id" => 32, 127 | "name" => "Espírito Santo", 128 | "abbr" => "ES", 129 | "created_at" => $now, 130 | "updated_at" => $now, 131 | ], [ 132 | "id" => 33, 133 | "name" => "Rio de Janeiro", 134 | "abbr" => "RJ", 135 | "created_at" => $now, 136 | "updated_at" => $now, 137 | ], [ 138 | "id" => 35, 139 | "name" => "São Paulo", 140 | "abbr" => "SP", 141 | "created_at" => $now, 142 | "updated_at" => $now, 143 | ], [ 144 | "id" => 41, 145 | "name" => "Paraná", 146 | "abbr" => "PR", 147 | "created_at" => $now, 148 | "updated_at" => $now, 149 | ], [ 150 | "id" => 42, 151 | "name" => "Santa Catarina", 152 | "abbr" => "SC", 153 | "created_at" => $now, 154 | "updated_at" => $now, 155 | ], [ 156 | "id" => 43, 157 | "name" => "Rio Grande do Sul", 158 | "abbr" => "RS", 159 | "created_at" => $now, 160 | "updated_at" => $now, 161 | ], [ 162 | "id" => 50, 163 | "name" => "Mato Grosso do Sul", 164 | "abbr" => "MS", 165 | "created_at" => $now, 166 | "updated_at" => $now, 167 | ], [ 168 | "id" => 51, 169 | "name" => "Mato Grosso", 170 | "abbr" => "MT", 171 | "created_at" => $now, 172 | "updated_at" => $now, 173 | ], [ 174 | "id" => 52, 175 | "name" => "Goiás", 176 | "abbr" => "GO", 177 | "created_at" => $now, 178 | "updated_at" => $now, 179 | ], [ 180 | "id" => 53, 181 | "name" => "Distrito Federal", 182 | "abbr" => "DF", 183 | "created_at" => $now, 184 | "updated_at" => $now, 185 | ], 186 | ]); 187 | 188 | } 189 | 190 | } 191 | --------------------------------------------------------------------------------