├── README.md ├── assets └── der.png ├── composer.json ├── sql ├── dump-cities-br.sql ├── dump-countries.sql └── dump-states-br.sql └── src ├── Config └── states-and-cities.php ├── Http └── Controllers │ ├── AddressesController.php │ ├── Api │ └── V1 │ │ ├── CitiesApiV1Controller.php │ │ ├── CountriesApiV1Controller.php │ │ └── StatesApiV1Controller.php │ ├── CitiesController.php │ ├── CountriesController.php │ └── StatesController.php ├── Lang ├── en │ ├── addresses.php │ ├── cities.php │ ├── countries.php │ └── states.php └── pt-br │ ├── cities.php │ ├── countries.php │ └── states.php ├── Migrations ├── 2017_12_01_120943_create_countries_table.php ├── 2017_12_01_174753_create_states_table.php ├── 2017_12_02_182814_create_cities_table.php └── 2017_12_05_114702_create_addresses_table.php ├── Models ├── Address.php ├── City.php ├── Country.php └── State.php ├── Providers └── StatesAndCitiesServiceProvider.php ├── Routes ├── api.php └── web.php ├── Seeds ├── CitiesTableSeeder.php ├── CountriesTableSeeder.php ├── DatabaseSeeder.php └── StatesBrTableSeeder.php ├── Views ├── addresses │ ├── create.blade.php │ ├── edit.blade.php │ ├── fields.blade.php │ └── index.blade.php ├── cities │ ├── create.blade.php │ ├── edit.blade.php │ └── index.blade.php ├── countries │ ├── create.blade.php │ ├── edit.blade.php │ └── index.blade.php └── states │ ├── create.blade.php │ ├── edit.blade.php │ └── index.blade.php └── assets └── js └── blit-states-and-cities.js /README.md: -------------------------------------------------------------------------------- 1 | # laravel-states-and-cities 2 | 3 | - Laravel. 4 | - País, estados e cidades. 5 | - Já populado com estados e cidades brasileiras com código do IBGE 6 | 7 | ### Tasks 8 | 9 | Lista de prioridades de novas implementações 10 | 11 | - Traid e contrato 12 | - Criar uma traid para que qualquer model (empresa,pessoa,fornecedores) possua endereços atraves de uma tabela pivo dinamica. 13 | - Melhorar o script JS 14 | - Consulta de CEP para selecionar estado e cidade automaticamente ao retornar o endereço do cep digitado. 15 | 16 | Ajude-nos! Vamos fazer isso juntos, faça seu fork! 17 | 18 | ### DER - RELATIONAL ENTITY DIAGRAM 19 | ![Image of Blit Softwares](./assets/der.png) 20 | 21 | ## Instalação 22 | 23 | Edite seu composer para instalar versoes dev. 24 | ``` 25 | "minimum-stability": "dev" 26 | ``` 27 | 28 | Via composer 29 | 30 | ``` 31 | composer require blitsoftwares/laravel-states-and-cities 32 | ``` 33 | 34 | ou manualmente adicione no seu composer.json 35 | 36 | ``` 37 | { 38 | "require": { 39 | "blitsoftwares/laravel-states-and-cities": "dev-master" 40 | } 41 | } 42 | ``` 43 | 44 | ### 2. Provider 45 | 46 | Se você está usando Laravel 5.5+ pule esta sessão, pois nosso pacote possui suporte à auto-discovery. 47 | 48 | ``` 49 | 'providers' => [ 50 | Blit\StatesAndCities\Providers\StatesAndCitiesServiceProvider::class, 51 | ], 52 | ``` 53 | 54 | ### 3. Migration 55 | 56 | Execute as migrações, as tabelas serão criadas em seu banco de dados; 57 | ``` 58 | php artisan migrate 59 | ``` 60 | 61 | ### 4. Seeder 62 | 63 | Atualmente está disponível via seeder o Brasil, com todos os estados e cidades. 64 | Estados e cidades possuem código do IBGE 65 | 66 | Quem desejar contribuir na implementação de novos países, fique à vontade, faça o fork, implemente os seeds e envie seu PullRequest. 67 | 68 | ``` 69 | php artisan db:seed --class=Blit\\StatesAndCities\\Seeds\\DatabaseSeeder 70 | ``` 71 | 72 | ### 5. Publish 73 | 74 | Publique os arquivos do pacote: 75 | 76 | ``` 77 | php artisan vendor:publish --provider=Blit\\StatesAndCities\\Providers\\StatesAndCitiesServiceProvider 78 | ``` 79 | 80 | #### Arquivos a serem publicados 81 | 82 | - Lang (traduções) 83 | - resources/lang/vendor/StatesAndCities 84 | - Views 85 | - resources/views/vendor/StatesAndCities 86 | - Assets 87 | - public/vendor/StatesAndCities 88 | - Config 89 | - config/states-and-cities.php 90 | 91 | ### 6. Routes 92 | 93 | Rotas disponíveis 94 | 95 | - /countries 96 | - /states 97 | - /cities 98 | - /addresses 99 | 100 | ### 7. Javascript 101 | 102 | Para que os selects entre países, estados e cidades fiquem dinâmicos, é necessário adicionar o JS do pacote, juntamente com o jquery.mask 103 | para que o campo de CEP fique com máscara. 104 | 105 | 6.1 - Adicione no fim do seu layout (template) 106 | ``` 107 | 108 | 109 | ``` 110 | 111 | ### Manualmente 112 | 113 | Caso você esteja integrar países, cidades e estados em seu formulário, basta adicionar os selects abaixo. 114 | 115 | Não mude o ID do componente, pois o JS usa ele para fazer os loads. 116 | O atributo NAME pode ser personalizado conforme sua tabela de endereços. 117 | 118 | Para países (necessário para load de estados) 119 | ``` 120 | 121 | ``` 122 | 123 | Para estados (necessário para o load de cidades) 124 | ``` 125 | 126 | ``` 127 | 128 | Para cidades 129 | ``` 130 | 131 | ``` 132 | 133 | Para CEP 134 | ``` 135 | 136 | ``` 137 | 138 | ### Configurações 139 | 140 | Na pasta config do laravel, se encontra publicado o arquivo de configuração do pacote: 141 | 142 | - states-and-cities.php 143 | 144 | Nele possi algumas variáveis que pode ser personalizada conforme sua necessidade: 145 | 146 | - default-country :: País padrão para o auto load 147 | - default-state :: Estado padrão para o auto load 148 | - default-city :: Cidade padrão para o auto load 149 | - postal_code_mask :: Padrão para máscara do CEP usando nosso componente 150 | - routes_middleware :: Middleware para as rotas 151 | 152 | Os valores a serem adicionados nas 3 primeiras variáveis são os IDs da sua respectiva tabela, acesse as rotas e olhe a coluna # que possui os ids dos registros. 153 | 154 | ### Auto preencher com CEP digitado 155 | 156 | O pacote está integrado com VIACEP. 157 | Para utilizar, use o componente de CEP na sessão MANUALMENTE e adicione os campos de endereços com os IDs abaixo: 158 | 159 | Para logradouro: 160 | ``` 161 | 162 | ``` 163 | 164 | Para bairro: 165 | ``` 166 | 167 | ``` 168 | 169 | Os seletores automáticos para estado e cidade após uma consulta do CEP, ainda será implementado. 170 | 171 | ## Traduções 172 | 173 | As views de cadastros nativas de países, estados, cidades e endereços, estão integradas com o LANG do laravel. 174 | Idiomas disponívies 175 | 176 | - Portugues Brasil (pt-br) 177 | - Inglês (en) 178 | 179 | Os arquivos estão disponíveis na pasta: 180 | 181 | - resources/lang/vendor/StatesAndCities 182 | 183 | Configure o locale do seu laravel. 184 | 185 | ## Informações 186 | 187 | Este pacote é mantido pela equipe de desenvolvedores da Blit Softwares. 188 | Faça um fork e nos ajude com novidades e eventuais falhas. 189 | 190 | - Contato 191 | - Blit Softwares 192 | - http://blitsoft.com.br 193 | 194 | 195 | -------------------------------------------------------------------------------- /assets/der.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blitsoftwares/laravel-states-and-cities/a158cbdf842893fc5048aadf5254a697c4f0a409/assets/der.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blitsoftwares/laravel-states-and-cities", 3 | "description": "País, cidades e estados. Com código IBGE Brasil. Com migrations, models, seeder, routes, config e views. SQL de dumps disponiveis na pasta 'sql'.", 4 | "type": "library", 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Lucas R.Pasquetto", 9 | "email": "lucas@blitsoft.com.br", 10 | "homepage": "http://www.blitsoft.com", 11 | "role": "Developer" 12 | } 13 | ], 14 | "require": { 15 | 16 | }, 17 | "autoload": { 18 | "psr-4": { 19 | "Blit\\StatesAndCities\\": "./src" 20 | } 21 | }, 22 | "extra": { 23 | "laravel":{ 24 | "providers": [ 25 | "Blit\\StatesAndCities\\Providers\\StatesAndCitiesServiceProvider" 26 | ] 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sql/dump-countries.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE TABLE `countries` ( 3 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 4 | `code_iso2` varchar(2) COLLATE utf8mb4_unicode_ci NOT NULL, 5 | `code_iso3` varchar(3) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 6 | `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, 7 | `code_phone` varchar(5) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 8 | `lang` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 9 | `created_at` timestamp NULL DEFAULT NULL, 10 | `updated_at` timestamp NULL DEFAULT NULL, 11 | PRIMARY KEY (`id`) 12 | ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 13 | 14 | INSERT INTO `countries` (`id`,`code_iso2`,`code_iso3`,`name`,`code_phone`,`lang`,`created_at`,`updated_at`) VALUES (1,'BR','BRA','Brazil','+55','pt-br','2017-12-03 17:20:11','2017-12-03 17:20:11'); 15 | -------------------------------------------------------------------------------- /sql/dump-states-br.sql: -------------------------------------------------------------------------------- 1 | 2 | CREATE TABLE `states` ( 3 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 4 | `country_id` int(11) NOT NULL, 5 | `ibge` int(11) NOT NULL, 6 | `code` varchar(2) COLLATE utf8mb4_unicode_ci NOT NULL, 7 | `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, 8 | `created_at` timestamp NULL DEFAULT NULL, 9 | `updated_at` timestamp NULL DEFAULT NULL, 10 | PRIMARY KEY (`id`) 11 | ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 12 | 13 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (1,1,12,'AC','Acre','2017-12-03 17:20:11','2017-12-03 17:20:11'); 14 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (2,1,27,'AL','Alagoas','2017-12-03 17:20:11','2017-12-03 17:20:11'); 15 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (3,1,16,'AP','Amapá','2017-12-03 17:20:11','2017-12-03 17:20:11'); 16 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (4,1,13,'AM','Amazonas','2017-12-03 17:20:11','2017-12-03 17:20:11'); 17 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (5,1,29,'BA','Bahia','2017-12-03 17:20:11','2017-12-03 17:20:11'); 18 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (6,1,23,'CE','Ceará','2017-12-03 17:20:11','2017-12-03 17:20:11'); 19 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (7,1,53,'DF','Distrito Federal','2017-12-03 17:20:11','2017-12-03 17:20:11'); 20 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (8,1,32,'ES','Espírito Santo','2017-12-03 17:20:11','2017-12-03 17:20:11'); 21 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (9,1,52,'GO','Goiás','2017-12-03 17:20:11','2017-12-03 17:20:11'); 22 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (10,1,21,'MA','Maranhão','2017-12-03 17:20:11','2017-12-03 17:20:11'); 23 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (11,1,51,'MT','Mato Grosso','2017-12-03 17:20:11','2017-12-03 17:20:11'); 24 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (12,1,50,'MS','Mato Grosso do Sul','2017-12-03 17:20:11','2017-12-03 17:20:11'); 25 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (13,1,31,'MG','Minas Gerais','2017-12-03 17:20:11','2017-12-03 17:20:11'); 26 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (14,1,15,'PA','Pará','2017-12-03 17:20:11','2017-12-03 17:20:11'); 27 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (15,1,25,'PB','Paraíba','2017-12-03 17:20:11','2017-12-03 17:20:11'); 28 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (16,1,41,'PR','Paraná','2017-12-03 17:20:11','2017-12-03 17:20:11'); 29 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (17,1,26,'PE','Pernambuco','2017-12-03 17:20:11','2017-12-03 17:20:11'); 30 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (18,1,22,'PI','Piauí','2017-12-03 17:20:11','2017-12-03 17:20:11'); 31 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (19,1,33,'RJ','Rio de Janeiro','2017-12-03 17:20:11','2017-12-03 17:20:11'); 32 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (20,1,24,'RN','Rio Grande do Norte','2017-12-03 17:20:11','2017-12-03 17:20:11'); 33 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (21,1,43,'RS','Rio Grande do Sul','2017-12-03 17:20:11','2017-12-03 17:20:11'); 34 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (22,1,11,'RO','Rondônia','2017-12-03 17:20:11','2017-12-03 17:20:11'); 35 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (23,1,14,'RR','Roraima','2017-12-03 17:20:11','2017-12-03 17:20:11'); 36 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (24,1,42,'SC','Santa Catarina','2017-12-03 17:20:11','2017-12-03 17:20:11'); 37 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (25,1,35,'SP','São Paulo','2017-12-03 17:20:11','2017-12-03 17:20:11'); 38 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (26,1,28,'SE','Sergipe','2017-12-03 17:20:11','2017-12-03 17:20:11'); 39 | INSERT INTO `states` (`id`,`country_id`,`ibge`,`code`,`name`,`created_at`,`updated_at`) VALUES (27,1,17,'TO','Tocantins','2017-12-03 17:20:11','2017-12-03 17:20:11'); 40 | -------------------------------------------------------------------------------- /src/Config/states-and-cities.php: -------------------------------------------------------------------------------- 1 | 1, 21 | 22 | /* 23 | * SET DEFAULT STATE USING PRIMARY_KEY 24 | * SEE # IN TABLE LIST 25 | * 26 | * default is 12 - Mato Grosso do Sul (MS) 27 | */ 28 | "default-state" => 12, 29 | 30 | /* 31 | * SET DEFAULT CITY USING PRIMARY_KEY 32 | * SEE # IN TABLE LIST 33 | * 34 | * default is 5123 - Campo Grande 35 | */ 36 | "default-city" => 5123, 37 | 38 | /* 39 | * MASKS 40 | */ 41 | 42 | "postal_code_mask" => "99999-999", 43 | 44 | /* 45 | * ROUTES MIDDLEWARE WEB 46 | */ 47 | "route_middleware" => ['web','auth'], 48 | 49 | /* 50 | * ROUTES MIDDLEWARE API 51 | */ 52 | "route_middleware_api" => ['auth:api','bindings'] 53 | ]; -------------------------------------------------------------------------------- /src/Http/Controllers/AddressesController.php: -------------------------------------------------------------------------------- 1 | $data]); 15 | } 16 | 17 | public function create() 18 | { 19 | return view('StatesAndCities::addresses.create'); 20 | } 21 | 22 | public function store(Request $request) 23 | { 24 | $input = $request->all(); 25 | Address::create($input); 26 | 27 | return redirect(route('addresses.index')); 28 | } 29 | 30 | public function edit($id) 31 | { 32 | $address = Address::find($id); 33 | 34 | return view('StatesAndCities::addresses.edit',['address'=>$address]); 35 | } 36 | 37 | public function update(Request $request, $id) 38 | { 39 | $input = $request->all(); 40 | $address = Address::find($id); 41 | $address->update($input); 42 | 43 | return redirect(route('addresses.index')); 44 | } 45 | 46 | public function destroy($id) 47 | { 48 | Address::destroy($id); 49 | return redirect(route('addresses.index')); 50 | } 51 | } -------------------------------------------------------------------------------- /src/Http/Controllers/Api/V1/CitiesApiV1Controller.php: -------------------------------------------------------------------------------- 1 | addDay(1); 18 | $data = []; 19 | if($state) { 20 | $state = State::code($state)->first(); 21 | if($state) { 22 | $data = Cache::remember('api::cities_'.$state->ibge, $lifeTime, function () use ($state) { 23 | return City::byState($state->id)->get(); 24 | }); 25 | } 26 | } else { 27 | $data = Cache::remember('api::cities',$lifeTime,function (){ 28 | return City::all(); 29 | }); 30 | } 31 | 32 | return $data; 33 | } 34 | 35 | public function show($code) 36 | { 37 | $city = City::find($code); 38 | if(!$city) 39 | { 40 | $city = City::byCode($code)->first(); 41 | } 42 | return $city; 43 | } 44 | 45 | public function store(Request $request) 46 | { 47 | Cache::forget('api::cities'); 48 | return City::create($request->all()); 49 | } 50 | 51 | public function update(Request $request, $id) 52 | { 53 | Cache::forget('api::cities'); 54 | $city = City::find($id); 55 | $city->update( $request->all()); 56 | return $city; 57 | } 58 | 59 | public function destroy($id) 60 | { 61 | Cache::forget('api::cities'); 62 | return City::destroy($id); 63 | } 64 | } -------------------------------------------------------------------------------- /src/Http/Controllers/Api/V1/CountriesApiV1Controller.php: -------------------------------------------------------------------------------- 1 | addDays(1); 16 | $data = Cache::remember('api::countries',$lifeTime,function (){ 17 | return Country::all(); 18 | }); 19 | return $data; 20 | } 21 | 22 | public function show($code) 23 | { 24 | $coutnry = Country::code($code)->first(); 25 | return $coutnry; 26 | } 27 | 28 | public function store(Request $request) 29 | { 30 | Cache::forget('api::countries'); 31 | return Country::create($request->all()); 32 | } 33 | 34 | public function update(Request $request, $id) 35 | { 36 | Cache::forget('api::countries'); 37 | $country = Country::find($id); 38 | $country->update($request->all()); 39 | return $country; 40 | } 41 | 42 | public function destroy($id) 43 | { 44 | Cache::forget('api::countries'); 45 | return Country::destroy($id); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/Http/Controllers/Api/V1/StatesApiV1Controller.php: -------------------------------------------------------------------------------- 1 | addDay(1); 17 | $data = []; 18 | if($country) { 19 | $country = Country::code($country)->first(); 20 | if($country) { 21 | $data = Cache::remember('api::states_'.$country->code_iso2, $lifeTime, function () use ($country) { 22 | return State::byCountry($country->id)->get(); 23 | }); 24 | } 25 | } else { 26 | $data = Cache::remember('api::states',$lifeTime,function (){ 27 | return State::all(); 28 | }); 29 | } 30 | 31 | return $data; 32 | } 33 | 34 | public function show($code) 35 | { 36 | return State::code($code)->first(); 37 | } 38 | 39 | public function store(Request $request) 40 | { 41 | Cache::forget('api::states'); 42 | return State::create($request->all()); 43 | } 44 | 45 | public function update(Request $request, $id) 46 | { 47 | Cache::forget('api::states'); 48 | $state = State::find($id); 49 | $state->update($request->all()); 50 | return $state; 51 | } 52 | 53 | public function destroy($state) 54 | { 55 | Cache::forget('api::states'); 56 | $state = State::find($state); 57 | return $state->destroy(); 58 | } 59 | } -------------------------------------------------------------------------------- /src/Http/Controllers/CitiesController.php: -------------------------------------------------------------------------------- 1 | $data]); 15 | } 16 | 17 | public function getList($state_id) 18 | { 19 | $data = City::byState($state_id)->get(); 20 | 21 | return response()->json($data); 22 | } 23 | 24 | public function create() 25 | { 26 | return view('StatesAndCities::cities.create'); 27 | } 28 | 29 | public function store(Request $request) 30 | { 31 | $input = $request->all(); 32 | City::create($input); 33 | 34 | return redirect(route('cities.index')); 35 | } 36 | 37 | public function edit($id) 38 | { 39 | $city = City::find($id); 40 | 41 | return view('StatesAndCities::cities.edit',['city'=>$city]); 42 | } 43 | 44 | public function update(Request $request, $id) 45 | { 46 | $input = $request->all(); 47 | $country = City::find($id); 48 | $country->update($input); 49 | 50 | return redirect(route('cities.index')); 51 | } 52 | 53 | public function destroy($id) 54 | { 55 | City::destroy($id); 56 | return redirect(route('cities.index')); 57 | } 58 | } -------------------------------------------------------------------------------- /src/Http/Controllers/CountriesController.php: -------------------------------------------------------------------------------- 1 | $data]); 16 | } 17 | 18 | public function getList() 19 | { 20 | $data = Country::all(); 21 | 22 | return response()->json($data); 23 | } 24 | 25 | public function create() 26 | { 27 | return view('StatesAndCities::countries.create'); 28 | } 29 | 30 | public function store(Request $request) 31 | { 32 | $input = $request->all(); 33 | Country::create($input); 34 | 35 | return redirect(route('countries.index')); 36 | } 37 | 38 | public function edit($id) 39 | { 40 | $country = Country::find($id); 41 | 42 | return view('StatesAndCities::countries.edit',['country'=>$country]); 43 | } 44 | 45 | public function update(Request $request, $id) 46 | { 47 | $input = $request->all(); 48 | $country = Country::find($id); 49 | $country->update($input); 50 | 51 | return redirect(route('countries.index')); 52 | } 53 | 54 | public function destroy($id) 55 | { 56 | Country::destroy($id); 57 | 58 | return redirect(route('countries.index')); 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /src/Http/Controllers/StatesController.php: -------------------------------------------------------------------------------- 1 | $data]); 17 | } 18 | 19 | public function getList($country_id) 20 | { 21 | $data = State::byCountry($country_id)->get(); 22 | 23 | return response()->json($data); 24 | } 25 | 26 | public function create() 27 | { 28 | $countries = Country::all(); 29 | 30 | return view('StatesAndCities::states.create',['countries'=>$countries]); 31 | } 32 | 33 | public function store(Request $request) 34 | { 35 | $input = $request->all(); 36 | State::create($input); 37 | 38 | return redirect(route('states.index')); 39 | } 40 | 41 | public function edit($id) 42 | { 43 | $state = State::find($id); 44 | $countries = Country::all(); 45 | 46 | return view('StatesAndCities::states.edit',['state'=>$state,'countries'=>$countries]); 47 | } 48 | 49 | public function update(Request $request, $id) 50 | { 51 | $input = $request->all(); 52 | $country = State::find($id); 53 | $country->update($input); 54 | 55 | return redirect(route('states.index')); 56 | } 57 | 58 | public function destroy($id) 59 | { 60 | State::destroy($id); 61 | 62 | return redirect(route('states.index')); 63 | } 64 | } -------------------------------------------------------------------------------- /src/Lang/en/addresses.php: -------------------------------------------------------------------------------- 1 | 'Addresses', 6 | 'new-register' => 'New register', 7 | 'route-back' => 'Back', 8 | 'action' => 'Action', 9 | 10 | 'submit' => 'Save', 11 | 'edit' => 'Edit', 12 | 'delete' => 'Delete', 13 | 14 | 'fields' => [ 15 | 'country' => 'Country', 16 | 'state' => 'State', 17 | 'city' => 'City', 18 | 'name' => 'Name', 19 | 'street' => 'Street', 20 | 'number' => 'Number', 21 | 'complement' => 'Complement', 22 | 'district' => 'District', 23 | 'postal_code' => 'Postal Code', 24 | ], 25 | 26 | 'table-header' => [ 27 | 'city' => 'City', 28 | 'name' => 'Name', 29 | 'street' => 'Street', 30 | 'number' => 'Number', 31 | 'complement' => 'Complement', 32 | 'district' => 'District', 33 | 'postal_code' => 'Postal Code', 34 | ], 35 | 36 | ]; -------------------------------------------------------------------------------- /src/Lang/en/cities.php: -------------------------------------------------------------------------------- 1 | 'Cities', 6 | 'new-register' => 'New register', 7 | 'route-back' => 'Back', 8 | 'action' => 'Action', 9 | 10 | 'submit' => 'Save', 11 | 'edit' => 'Edit', 12 | 'delete' => 'Delete', 13 | 14 | 'fields' => [ 15 | 'country' => 'Country', 16 | 'state' => 'State', 17 | 'code' => 'Code', 18 | 'name' => 'Name', 19 | ], 20 | 21 | 'table-header' => [ 22 | 'country' => 'Country', 23 | 'state' => 'State', 24 | 'code' => 'Code', 25 | 'name' => 'Name', 26 | ], 27 | 28 | ]; -------------------------------------------------------------------------------- /src/Lang/en/countries.php: -------------------------------------------------------------------------------- 1 | 'Countries', 6 | 'new-register' => 'New register', 7 | 'route-back' => 'Back', 8 | 'action' => 'Action', 9 | 'states' => 'States', 10 | 'cities' => 'Cities', 11 | 12 | 'submit' => 'Save', 13 | 'edit' => 'Edit', 14 | 'delete' => 'Delete', 15 | 16 | 'fields' => [ 17 | 'name' => 'Name', 18 | 'code_phone' => 'Phone code (ex: +55)', 19 | 'code_iso2' => 'ISO-2 (ex: BR)', 20 | 'code_iso3' => 'ISO-3 (ex: BRA)', 21 | 'lang' => 'Lang (ex: pt-br)', 22 | ], 23 | 24 | 'table-header' => [ 25 | 'name' => 'Name', 26 | 'code_phone' => 'Phone code', 27 | 'code_iso2' => 'ISO-2', 28 | 'code_iso3' => 'ISO-3', 29 | 'lang' => 'Lang', 30 | ], 31 | 32 | 'country' => [ 33 | 'Brazil' => 'Brazil', 34 | ] 35 | 36 | ]; -------------------------------------------------------------------------------- /src/Lang/en/states.php: -------------------------------------------------------------------------------- 1 | 'States', 6 | 'new-register' => 'New register', 7 | 'route-back' => 'Back', 8 | 'action' => 'Action', 9 | 10 | 'submit' => 'Save', 11 | 'edit' => 'Edit', 12 | 'delete' => 'Delete', 13 | 14 | 'fields' => [ 15 | 'country' => 'Country', 16 | 'name' => 'Name', 17 | 'code' => 'Code', 18 | 'ibge' => 'National Code', 19 | ], 20 | 21 | 'table-header' => [ 22 | 'country' => 'Country', 23 | 'name' => 'Name', 24 | 'code' => 'Code', 25 | 'cities' => 'Cities', 26 | 'ibge' => 'National Code', 27 | ], 28 | 29 | ]; -------------------------------------------------------------------------------- /src/Lang/pt-br/cities.php: -------------------------------------------------------------------------------- 1 | 'Cidades', 6 | 'new-register' => 'Novo Registro', 7 | 'route-back' => 'Voltar', 8 | 'action' => 'Ação', 9 | 10 | 'submit' => 'Salvar', 11 | 'edit' => 'Editar', 12 | 'delete' => 'Deletar', 13 | 14 | 'fields' => [ 15 | 'country' => 'País', 16 | 'state' => 'Estado', 17 | 'code' => 'IBGE', 18 | 'name' => 'Nome', 19 | ], 20 | 21 | 'table-header' => [ 22 | 'country' => 'País', 23 | 'state' => 'Estado', 24 | 'code' => 'IBGE', 25 | 'name' => 'Nome', 26 | ], 27 | 28 | ]; -------------------------------------------------------------------------------- /src/Lang/pt-br/countries.php: -------------------------------------------------------------------------------- 1 | 'Países', 6 | 'new-register' => 'Novo registro', 7 | 'route-back' => 'Voltar', 8 | 'action' => 'Ação', 9 | 'states' => 'Estados', 10 | 'cities' => 'Cidades', 11 | 12 | 'submit' => 'Salvar', 13 | 'edit' => 'Editar', 14 | 'delete' => 'Deletar', 15 | 16 | 'fields' => [ 17 | 'name' => 'Nome', 18 | 'code_phone' => 'Código de área (ex: +55)', 19 | 'code_iso2' => 'ISO-2 (ex: BR)', 20 | 'code_iso3' => 'ISO-3 (ex: BRA)', 21 | 'lang' => 'Idioma (ex: pt-br)', 22 | ], 23 | 24 | 'table-header' => [ 25 | 'name' => 'Nome', 26 | 'code_phone' => 'Código de área', 27 | 'code_iso2' => 'ISO-2', 28 | 'code_iso3' => 'ISO-3', 29 | 'lang' => 'Idioma', 30 | ], 31 | 32 | 'country' => [ 33 | 'Brazil' => 'Brasil', 34 | ] 35 | 36 | ]; -------------------------------------------------------------------------------- /src/Lang/pt-br/states.php: -------------------------------------------------------------------------------- 1 | 'Estados', 6 | 'new-register' => 'Novo registro', 7 | 'route-back' => 'Voltar', 8 | 'action' => 'Ação', 9 | 10 | 'submit' => 'Salvar', 11 | 'edit' => 'Editar', 12 | 'delete' => 'Deletar', 13 | 14 | 'fields' => [ 15 | 'country' => 'País', 16 | 'name' => 'Nome', 17 | 'code' => 'UF', 18 | 'ibge' => 'IBGE', 19 | ], 20 | 21 | 'table-header' => [ 22 | 'country' => 'País', 23 | 'name' => 'Nome', 24 | 'code' => 'UF', 25 | 'cities' => 'Cidades', 26 | 'ibge' => 'IBGE', 27 | ], 28 | 29 | ]; -------------------------------------------------------------------------------- /src/Migrations/2017_12_01_120943_create_countries_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('code_iso2',2); 19 | $table->string('code_iso3',3)->nullable(); 20 | $table->string('name',255); 21 | $table->string('code_phone',5)->nullable(); 22 | $table->string('lang')->nullable(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('countries'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Migrations/2017_12_01_174753_create_states_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->integer('country_id'); 19 | $table->integer('ibge'); 20 | $table->string('code',2); 21 | $table->string('name',255); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('states'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Migrations/2017_12_02_182814_create_cities_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->integer('state_id'); 19 | $table->bigInteger('code'); 20 | $table->string('name'); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('cities'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Migrations/2017_12_05_114702_create_addresses_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->integer('city_id'); 19 | $table->string('name')->nullable(); 20 | $table->string('street')->nullable(); 21 | $table->string('number',10)->nullable(); 22 | $table->string('complement')->nullable(); 23 | $table->string('district')->nullable(); 24 | $table->string('postal_code',45)->nullable(); 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('addresses'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Models/Address.php: -------------------------------------------------------------------------------- 1 | belongsTo(City::class); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /src/Models/City.php: -------------------------------------------------------------------------------- 1 | where('state_id',$state); 23 | } 24 | 25 | /** 26 | * @param $query 27 | * @param $code 28 | * @return mixed 29 | */ 30 | public function scopeByCode($query,$code) 31 | { 32 | return $query->where('code',intval($code)); 33 | } 34 | 35 | /** 36 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 37 | */ 38 | public function state() 39 | { 40 | return $this->belongsTo(State::class); 41 | } 42 | 43 | /** 44 | * @return \Illuminate\Database\Eloquent\Relations\HasMany 45 | */ 46 | public function addresses() 47 | { 48 | return $this->hasMany(Address::class); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /src/Models/Country.php: -------------------------------------------------------------------------------- 1 | where('id',$code); 21 | } elseif (is_string($code)) { 22 | $qry = $query->where('code_iso2',$code); 23 | } 24 | 25 | return $qry; 26 | } 27 | 28 | 29 | public function states() 30 | { 31 | return $this->hasMany(State::class); 32 | } 33 | 34 | public function cities() 35 | { 36 | return $this->hasManyThrough(City::class,State::class); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/Models/State.php: -------------------------------------------------------------------------------- 1 | where('id',$code); 20 | } elseif (is_string($code)) { 21 | $qry = $query->where('code',$code); 22 | } 23 | 24 | return $qry; 25 | } 26 | 27 | public function scopeByCountry($query,$country) 28 | { 29 | return $query->where('country_id',$country); 30 | } 31 | 32 | public function country() 33 | { 34 | return $this->belongsTo(Country::class); 35 | } 36 | 37 | public function cities() 38 | { 39 | return $this->hasMany(City::class); 40 | } 41 | 42 | public function addresses() 43 | { 44 | return $this->hasManyThrough(Address::class,City::class); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /src/Providers/StatesAndCitiesServiceProvider.php: -------------------------------------------------------------------------------- 1 | middleware(config('states-and-cities.route_middleware')) 35 | ->group($routeDir); 36 | 37 | /* 38 | * ROUTES API 39 | */ 40 | Route::namespace("Blit\\StatesAndCities\\Http\\Controllers\Api\V1") 41 | ->middleware(config('states-and-cities.route_middleware_api')) 42 | ->group($routeApiDir); 43 | 44 | /* 45 | * LOAD RESOURCES 46 | */ 47 | $this->loadMigrationsFrom($migrationsDir); 48 | $this->loadTranslationsFrom($langDir,'StatesAndCities'); 49 | $this->loadViewsFrom($viewsDir,'StatesAndCities'); 50 | 51 | /* 52 | * PUBLISHER DATA 53 | */ 54 | $this->publishes([$langDir => resource_path('lang/vendor/StatesAndCities')],'laravel-states-and-cities-lang'); 55 | $this->publishes([$viewsDir => resource_path('views/vendor/StatesAndCities')],'laravel-states-and-cities-views'); 56 | $this->publishes([$publicDir => public_path('vendor/StatesAndCities')],'laravel-states-and-cities-assets'); 57 | $this->publishes([$configDir => config_path('states-and-cities.php')],'laravel-states-and-cities-config'); 58 | 59 | } 60 | 61 | public function register() 62 | { 63 | /* 64 | * MERGE CONFIG 65 | */ 66 | $this->mergeConfigFrom(__DIR__ . '/../Config/states-and-cities.php','states-and-cities'); 67 | } 68 | } -------------------------------------------------------------------------------- /src/Routes/api.php: -------------------------------------------------------------------------------- 1 | group(function (){ 6 | 7 | Route::resources([ 8 | 'countries'=>'CountriesApiV1Controller', 9 | 'states'=>'StatesApiV1Controller', 10 | 'cities'=>'CitiesApiV1Controller' 11 | ]); 12 | 13 | Route::get('countries/{country}/states','StatesApiV1Controller@index'); 14 | Route::get('states/{state}/cities','CitiesApiV1Controller@index'); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /src/Routes/web.php: -------------------------------------------------------------------------------- 1 | 'BR', 19 | 'code_iso3' => 'BRA', 20 | 'name' => 'Brazil', 21 | 'code_phone' => '+55', 22 | 'lang' => 'pt-br', 23 | ] 24 | ]; 25 | 26 | foreach($data as $reg) 27 | { 28 | \Blit\StatesAndCities\Models\Country::firstOrCreate($reg); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(CountriesTableSeeder::class); 17 | $this->call(StatesBrTableSeeder::class); 18 | $this->call(CitiesTableSeeder::class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Seeds/StatesBrTableSeeder.php: -------------------------------------------------------------------------------- 1 | first()->id; 19 | 20 | State::firstOrCreate( [ 21 | 'country_id'=> $country_id, 22 | 'ibge'=>12, 23 | 'name'=>'Acre', 24 | 'code'=>'AC' 25 | ] ); 26 | 27 | State::firstOrCreate( [ 28 | 'country_id'=> $country_id, 29 | 'ibge'=>27, 30 | 'name'=>'Alagoas', 31 | 'code'=>'AL' 32 | ] ); 33 | 34 | State::firstOrCreate( [ 35 | 'country_id'=> $country_id, 36 | 'ibge'=>16, 37 | 'name'=>'Amapá', 38 | 'code'=>'AP' 39 | ] ); 40 | 41 | State::firstOrCreate( [ 42 | 'country_id'=> $country_id, 43 | 'ibge'=>13, 44 | 'name'=>'Amazonas', 45 | 'code'=>'AM' 46 | ] ); 47 | 48 | State::firstOrCreate( [ 49 | 'country_id'=> $country_id, 50 | 'ibge'=>29, 51 | 'name'=>'Bahia', 52 | 'code'=>'BA' 53 | ] ); 54 | 55 | State::firstOrCreate( [ 56 | 'country_id'=> $country_id, 57 | 'ibge'=>23, 58 | 'name'=>'Ceará', 59 | 'code'=>'CE' 60 | ] ); 61 | 62 | State::firstOrCreate( [ 63 | 'country_id'=> $country_id, 64 | 'ibge'=>53, 65 | 'name'=>'Distrito Federal', 66 | 'code'=>'DF' 67 | ] ); 68 | 69 | State::firstOrCreate( [ 70 | 'country_id'=> $country_id, 71 | 'ibge'=>32, 72 | 'name'=>'Espírito Santo', 73 | 'code'=>'ES' 74 | ] ); 75 | 76 | State::firstOrCreate( [ 77 | 'country_id'=> $country_id, 78 | 'ibge'=>52, 79 | 'name'=>'Goiás', 80 | 'code'=>'GO' 81 | ] ); 82 | 83 | State::firstOrCreate( [ 84 | 'country_id'=> $country_id, 85 | 'ibge'=>21, 86 | 'name'=>'Maranhão', 87 | 'code'=>'MA' 88 | ] ); 89 | 90 | State::firstOrCreate( [ 91 | 'country_id'=> $country_id, 92 | 'ibge'=>51, 93 | 'name'=>'Mato Grosso', 94 | 'code'=>'MT' 95 | ] ); 96 | 97 | State::firstOrCreate( [ 98 | 'country_id'=> $country_id, 99 | 'ibge'=>50, 100 | 'name'=>'Mato Grosso do Sul', 101 | 'code'=>'MS' 102 | ] ); 103 | 104 | State::firstOrCreate( [ 105 | 'country_id'=> $country_id, 106 | 'ibge'=>31, 107 | 'name'=>'Minas Gerais', 108 | 'code'=>'MG' 109 | ] ); 110 | 111 | State::firstOrCreate( [ 112 | 'country_id'=> $country_id, 113 | 'ibge'=>15, 114 | 'name'=>'Pará', 115 | 'code'=>'PA' 116 | ] ); 117 | 118 | State::firstOrCreate( [ 119 | 'country_id'=> $country_id, 120 | 'ibge'=>25, 121 | 'name'=>'Paraíba', 122 | 'code'=>'PB' 123 | ] ); 124 | 125 | State::firstOrCreate( [ 126 | 'country_id'=> $country_id, 127 | 'ibge'=>41, 128 | 'name'=>'Paraná', 129 | 'code'=>'PR' 130 | ] ); 131 | 132 | State::firstOrCreate( [ 133 | 'country_id'=> $country_id, 134 | 'ibge'=>26, 135 | 'name'=>'Pernambuco', 136 | 'code'=>'PE' 137 | ] ); 138 | 139 | State::firstOrCreate( [ 140 | 'country_id'=> $country_id, 141 | 'ibge'=>22, 142 | 'name'=>'Piauí', 143 | 'code'=>'PI' 144 | ] ); 145 | 146 | State::firstOrCreate( [ 147 | 'country_id'=> $country_id, 148 | 'ibge'=>33, 149 | 'name'=>'Rio de Janeiro', 150 | 'code'=>'RJ' 151 | ] ); 152 | 153 | State::firstOrCreate( [ 154 | 'country_id'=> $country_id, 155 | 'ibge'=>24, 156 | 'name'=>'Rio Grande do Norte', 157 | 'code'=>'RN' 158 | ] ); 159 | 160 | State::firstOrCreate( [ 161 | 'country_id'=> $country_id, 162 | 'ibge'=>43, 163 | 'name'=>'Rio Grande do Sul', 164 | 'code'=>'RS' 165 | ] ); 166 | 167 | State::firstOrCreate( [ 168 | 'country_id'=> $country_id, 169 | 'ibge'=>11, 170 | 'name'=>'Rondônia', 171 | 'code'=>'RO' 172 | ] ); 173 | 174 | State::firstOrCreate( [ 175 | 'country_id'=> $country_id, 176 | 'ibge'=>14, 177 | 'name'=>'Roraima', 178 | 'code'=>'RR' 179 | ] ); 180 | 181 | State::firstOrCreate( [ 182 | 'country_id'=> $country_id, 183 | 'ibge'=>42, 184 | 'name'=>'Santa Catarina', 185 | 'code'=>'SC' 186 | ] ); 187 | 188 | State::firstOrCreate( [ 189 | 'country_id'=> $country_id, 190 | 'ibge'=>35, 191 | 'name'=>'São Paulo', 192 | 'code'=>'SP' 193 | ] ); 194 | 195 | State::firstOrCreate( [ 196 | 'country_id'=> $country_id, 197 | 'ibge'=>28, 198 | 'name'=>'Sergipe', 199 | 'code'=>'SE' 200 | ] ); 201 | 202 | State::firstOrCreate( [ 203 | 'country_id'=> $country_id, 204 | 'ibge'=>17, 205 | 'name'=>'Tocantins', 206 | 'code'=>'TO' 207 | ] ); 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/Views/addresses/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |
9 |

{{ trans('StatesAndCities::addresses.addresses') }}

10 |
11 |
12 |
13 | {{ csrf_field() }} 14 | 15 | 16 | 17 |
18 | 19 | 20 |
21 | 22 |
23 | 24 | 25 |
26 | 27 |
28 | 29 | 30 |
31 | 32 |
33 | 34 | 35 |
36 | 37 |
38 | 39 | 40 |
41 | 42 | 43 |
44 | 45 | 46 |
47 | 48 |
49 | 50 | 51 |
52 |
53 | 54 | 55 |
56 |
57 | 58 | 59 |
60 | 61 |
62 |
63 | 66 |
67 |
68 |
69 |
70 |
71 | @endsection 72 | -------------------------------------------------------------------------------- /src/Views/addresses/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::addresses.addresses') }}

9 |
10 |
11 |
12 | 13 | 14 | {{ csrf_field() }} 15 | 16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 |
32 | 33 | 34 |
35 | 36 |
37 | 38 | 39 |
40 | 41 | 42 |
43 | 44 | 45 |
46 | 47 |
48 | 49 | 50 |
51 |
52 | 53 | 54 |
55 |
56 | 57 | 58 |
59 | 60 |
61 |
62 | 65 |
66 |
67 |
68 |
69 |
70 | @endsection 71 | -------------------------------------------------------------------------------- /src/Views/addresses/fields.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 |
7 | 8 | 9 |
10 | 11 |
12 | 13 | 14 |
15 | 16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 |
32 | 33 | 34 |
35 |
36 | 37 | 38 |
39 |
40 | 41 | 42 |
-------------------------------------------------------------------------------- /src/Views/addresses/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::addresses.addresses') }}

9 |
10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | @foreach($data as $obj) 25 | 26 | 27 | 33 | 34 | 35 | 36 | 37 | 47 | 48 | @endforeach 49 | 50 | 51 |
#{{ trans('StatesAndCities::addresses.table-header.street') }}{{ trans('StatesAndCities::addresses.table-header.number') }}{{ trans('StatesAndCities::addresses.table-header.district') }}{{ trans('StatesAndCities::addresses.table-header.postal_code') }}{{ trans('StatesAndCities::addresses.table-header.city') }}{{ trans('StatesAndCities::addresses.action') }}
{{ $obj->id }} 28 | {{ $obj->street }} 29 | @if($obj->name || $obj->complement)
@endif 30 | @if($obj->complement){{ $obj->complement }}@endif 31 | @if($obj->name)*{{ $obj->name }}@endif 32 |
{{ $obj->number }}{{ $obj->district }}{{ $obj->postal_code }}{{ $obj->city->name }}/{{ $obj->city->state->code }} 38 |
39 |
40 | 41 | {{ csrf_field() }} 42 | 43 | 44 |
45 |
46 |
52 | {!! $data->render() !!} 53 |
54 |
55 | @endsection 56 | -------------------------------------------------------------------------------- /src/Views/cities/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::cities.cities') }}

9 |
10 |
11 |
12 | {{ csrf_field() }} 13 | 14 |
15 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 | 30 |
31 |
32 |
33 | 34 |
35 | 36 |
37 |
38 |
39 |
40 | 43 |
44 |
45 |
46 |
47 |
48 | @endsection 49 | -------------------------------------------------------------------------------- /src/Views/cities/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::cities.cities') }}

9 |
10 |
11 |
12 | 13 | 14 | {{ csrf_field() }} 15 | 16 |
17 | 18 |
19 | 20 |
21 |
22 | 23 |
24 | 25 |
26 | 27 |
28 |
29 | 30 |
31 | 32 |
33 | 34 |
35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 43 |
44 |
45 | 48 |
49 |
50 |
51 |
52 |
53 | @endsection 54 | -------------------------------------------------------------------------------- /src/Views/cities/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::cities.cities') }}

9 |
10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | @foreach($data as $obj) 24 | 25 | 26 | 27 | 28 | 29 | 30 | 40 | 41 | @endforeach 42 | 43 | 44 |
#{{ trans('StatesAndCities::cities.table-header.code') }}{{ trans('StatesAndCities::cities.table-header.name') }}{{ trans('StatesAndCities::cities.table-header.state') }}{{ trans('StatesAndCities::cities.table-header.country') }}{{ trans('StatesAndCities::cities.action') }}
{{ $obj->id }}{{ $obj->code }}{{ $obj->name }}{{ $obj->state->code }}{{ $obj->state->country->code_iso2 }} 31 |
32 |
33 | 34 | {{ csrf_field() }} 35 | 36 | 37 |
38 |
39 |
45 | {!! $data->render() !!} 46 |
47 |
48 | @endsection 49 | -------------------------------------------------------------------------------- /src/Views/countries/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::countries.countries') }}

9 |
10 |
11 |
12 | {{ csrf_field() }} 13 | 14 |
15 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 | 30 |
31 |
32 |
33 | 34 |
35 | 36 |
37 |
38 |
39 | 40 |
41 | 42 |
43 |
44 | 45 |
46 |
47 | 50 |
51 |
52 |
53 |
54 |
55 | @endsection 56 | -------------------------------------------------------------------------------- /src/Views/countries/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::countries.countries') }}

9 |
10 |
11 |
12 | 13 | 14 | {{ csrf_field() }} 15 | 16 |
17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 |
28 |
29 | 30 |
31 | 32 |
33 |
34 |
35 | 36 |
37 | 38 |
39 |
40 |
41 | 42 |
43 | 44 |
45 |
46 | 47 |
48 |
49 | 52 |
53 |
54 |
55 |
56 |
57 | @endsection 58 | -------------------------------------------------------------------------------- /src/Views/countries/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::countries.countries') }}

9 |
10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | @foreach($data as $obj) 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 46 | 47 | @endforeach 48 | 49 | 50 |
#{{ trans('StatesAndCities::countries.table-header.name') }}{{ trans('StatesAndCities::countries.table-header.code_iso2') }}{{ trans('StatesAndCities::countries.table-header.code_iso3') }}{{ trans('StatesAndCities::countries.table-header.code_phone') }}{{ trans('StatesAndCities::countries.table-header.lang') }}{{ trans('StatesAndCities::countries.states') }}{{ trans('StatesAndCities::countries.cities') }}{{ trans('StatesAndCities::countries.action') }}
{{ $obj->id }}{{ trans('StatesAndCities::countries.country.'.$obj->name) }}{{ $obj->code_iso2 }}{{ $obj->code_iso3 }}{{ $obj->code_phone }}{{ $obj->lang }}{{ $obj->states()->count() }}{{ $obj->cities()->count() }} 37 |
38 |
39 | 40 | {{ csrf_field() }} 41 | 42 | 43 |
44 |
45 |
51 |
52 |
53 | @endsection 54 | -------------------------------------------------------------------------------- /src/Views/states/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::states.states') }}

9 |
10 |
11 |
12 | {{ csrf_field() }} 13 | 14 |
15 | 16 |
17 | 18 |
19 |
20 |
21 | 22 |
23 | 24 |
25 |
26 |
27 | 28 |
29 | 30 |
31 |
32 |
33 | 34 |
35 | 36 |
37 |
38 |
39 |
40 | 43 |
44 |
45 |
46 |
47 |
48 | @endsection 49 | -------------------------------------------------------------------------------- /src/Views/states/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::states.states') }}

9 |
10 |
11 |
12 | 13 | 14 | {{ csrf_field() }} 15 | 16 |
17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 |
28 |
29 | 30 |
31 | 32 |
33 |
34 |
35 | 36 |
37 | 38 |
39 |
40 | 41 |
42 |
43 | 46 |
47 |
48 |
49 |
50 |
51 | @endsection 52 | -------------------------------------------------------------------------------- /src/Views/states/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |

{{ trans('StatesAndCities::states.states') }}

9 |
10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | @foreach($data as $obj) 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 42 | 43 | @endforeach 44 | 45 | 46 |
#{{ trans('StatesAndCities::states.table-header.code') }}{{ trans('StatesAndCities::states.table-header.name') }}{{ trans('StatesAndCities::states.table-header.ibge') }}{{ trans('StatesAndCities::states.table-header.cities') }}{{ trans('StatesAndCities::states.table-header.country') }}{{ trans('StatesAndCities::states.action') }}
{{ $obj->id }}{{ $obj->code }}{{ $obj->name }}{{ $obj->ibge }}{{ $obj->cities()->count() }}{{ $obj->country->code_iso2 }} 33 |
34 |
35 | 36 | {{ csrf_field() }} 37 | 38 | 39 |
40 |
41 |
47 |
48 |
49 | @endsection 50 | -------------------------------------------------------------------------------- /src/assets/js/blit-states-and-cities.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | 3 | var cmp_postal_code = $('#postal_code'); 4 | cmp_postal_code.mask(cmp_postal_code.attr('data-mask')); 5 | 6 | $('#country').countries({ 7 | onChange: function(country_id){ 8 | $('#state').ufs({ 9 | country_id: country_id, 10 | onChange: function(uf_id){ 11 | $('#city').cidades({uf: uf_id}); 12 | } 13 | }); 14 | } 15 | }); 16 | 17 | if(cmp_postal_code.attr('data-autocomplete')) 18 | { 19 | cmp_postal_code.findAddressByCep() 20 | } 21 | 22 | }) 23 | 24 | $.fn.findAddressByCep = function() { 25 | var input = $(this); 26 | 27 | var settings = $.extend({ 28 | 'onBlur': function(){ 29 | $('#street').val('loading...'); 30 | $('#district').val('loading...'); 31 | 32 | var postal_code = input.val().toString().replace('-',''); 33 | 34 | $.get("http://viacep.com.br/ws/"+postal_code+"/json/", null, function (json) { 35 | 36 | /** 37 | * RETURN VIACEP.COM.BR FOR BRAZIL 38 | * 39 | * { 40 | * "cep": "01001-000", 41 | * "logradouro": "Praça da Sé", 42 | * "complemento": "lado ímpar", 43 | * "bairro": "Sé", 44 | * "localidade": "São Paulo", 45 | * "uf": "SP", 46 | * "unidade": "", 47 | * "ibge": "3550308", 48 | * "gia": "1004" 49 | * } 50 | */ 51 | 52 | $('#street').val(json.logradouro); 53 | $('#district').val(json.bairro); 54 | $('#number').focus(); 55 | 56 | }, 'json'); 57 | } 58 | }); 59 | 60 | input.blur(function(){ 61 | settings.onBlur(input.val()); 62 | }); 63 | 64 | } 65 | 66 | $.fn.countries = function(options) { 67 | 68 | var select = $(this); 69 | 70 | var settings = $.extend({ 71 | 'default': select.attr('data-default'), 72 | 'onChange': function(id){} 73 | }, options ); 74 | 75 | $.get("/countries-list", null, function (json) { 76 | 77 | select.empty(); 78 | $.each(json, function (key, value) { 79 | select.append(''); 80 | }) 81 | 82 | settings.onChange(select.val()); 83 | 84 | 85 | }, 'json'); 86 | 87 | select.change(function(){ 88 | settings.onChange(select.val()); 89 | }); 90 | }; 91 | 92 | $.fn.ufs = function(options) { 93 | 94 | var select = $(this); 95 | 96 | var settings = $.extend({ 97 | 'default': select.attr('data-default'), 98 | 'onChange': function(uf){} 99 | }, options ); 100 | 101 | $.get("/states-list/"+options.country_id, null, function (json) { 102 | 103 | select.empty(); 104 | select.html(''); 105 | $.each(json, function (key, value) { 106 | select.append(''); 107 | }) 108 | 109 | settings.onChange(select.val()); 110 | 111 | }, 'json'); 112 | 113 | select.change(function(){ 114 | settings.onChange(select.val()); 115 | }); 116 | }; 117 | 118 | 119 | $.fn.cidades = function(options) { 120 | 121 | var select = $(this); 122 | 123 | var settings = $.extend({ 124 | 'default': select.attr('data-default'), 125 | 'uf': null 126 | }, options ); 127 | 128 | if(settings.uf == null) 129 | console.warn('Nenhuma UF informada'); 130 | else{ 131 | 132 | select.html(''); 133 | 134 | $.get("/cities-list/"+options.uf, null, function (json) { 135 | select.empty(); 136 | select.html(''); 137 | $.each(json, function (key, value) { 138 | select.append(''); 139 | }) 140 | 141 | }, 'json'); 142 | 143 | 144 | } 145 | }; --------------------------------------------------------------------------------