paulofelipem/brazilian-regions 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

paulofelipem/brazilian-regions

最新稳定版本:v1.0.20

Composer 安装命令:

composer require paulofelipem/brazilian-regions

包简介

Pacote com informações de todos os paises, estados e cidades (Estados e cidades brasileiras).

README 文档

README

Latest Version on Packagist Total Downloads License: MIT

A Laravel package that provides migrations, seeders, and Eloquent models for countries, states, and cities — with full data for all Brazilian states and municipalities.

Data sourced from the IBGE Localities API.

Features

  • All world countries with M49 codes and region classification
  • All 27 Brazilian states with regional data
  • All Brazilian municipalities (5,000+)
  • Ready-to-use Eloquent models with relationships
  • Fully configurable table names, column names, and models
  • Auto-discovery support for Laravel 9+

Requirements

  • PHP 8.1+
  • Laravel 9.0+

Installation

Install the package via Composer:

composer require paulofelipem/brazilian-regions

The service provider is registered automatically. If needed, you can register it manually in config/app.php:

'providers' => [
    // ...
    PauloFelipeM\BrazilianRegions\BrazilianRegionsServiceProvider::class,
],

Publish the configuration and migration files:

php artisan vendor:publish --provider="PauloFelipeM\BrazilianRegions\BrazilianRegionsServiceProvider"

Note: This publishes a config/brazilianregions.php file. If you already have a file with that name, rename or remove it before publishing.

Usage

Run the migrations and seeders to create and populate the tables:

php artisan migrate
php artisan db:seed --class="PauloFelipeM\\BrazilianRegions\\Database\\Seeds\\DatabaseSeeder"

Then use the provided Eloquent models in your application:

use PauloFelipeM\BrazilianRegions\Models\Country;
use PauloFelipeM\BrazilianRegions\Models\State;
use PauloFelipeM\BrazilianRegions\Models\City;

// Get all Brazilian states
$brazil = Country::where('acronym', 'BRA')->first();
$states = $brazil->states;

// Get all cities in a state
$state = State::where('acronym', 'SP')->first();
$cities = $state->cities;

// Navigate from city to country
$city = City::where('name', 'São Paulo')->first();
$state = $city->state;
$country = $city->state->country;

Database Schema

countries

Column Description
id Auto-increment primary key
m_49 UN M49 numeric code
acronym ISO Alpha-3 country code
name Country name
region Geographic region

states

Column Description
id Auto-increment primary key
acronym State abbreviation (e.g. SP, RJ)
name State name
region Region name (e.g. Sudeste)
region_acronym Region abbreviation
country_id Foreign key to countries

cities

Column Description
id Auto-increment primary key
name City name
state_id Foreign key to states

All foreign keys use CASCADE on delete.

Configuration

The published config/brazilianregions.php file allows you to customize:

return [
    // Override the default Eloquent models
    'models' => [
        'country' => PauloFelipeM\BrazilianRegions\Models\Country::class,
        'state'   => PauloFelipeM\BrazilianRegions\Models\State::class,
        'city'    => PauloFelipeM\BrazilianRegions\Models\City::class,
    ],

    // Customize table names
    'tables' => [
        'countries' => 'countries',
        'states'    => 'states',
        'cities'    => 'cities',
    ],

    // Customize foreign key column names
    'columns' => [
        'country_id' => 'country_id',
        'state_id'   => 'state_id',
        'city_id'    => 'city_id',
    ],
];

This is useful when you need to integrate with an existing database schema or extend the default models.

Changelog

See CHANGELOG for release history.

Bugs

If you find any issues, please open an issue on GitHub.

Credits

License

The MIT License (MIT). See LICENSE for more information.

统计信息

  • 总下载量: 470
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-11-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固