blamodex/laravel-addresses 问题修复 & 功能扩展

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

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

blamodex/laravel-addresses

Composer 安装命令:

composer require blamodex/laravel-addresses

包简介

Address management package for Laravel applications.

README 文档

README

License: MIT Laravel PHP Tests

A lightweight Laravel package to manage postal addresses, countries and administrative areas, suitable for attaching addresses to any Eloquent model using polymorphic relationships.

📋 Table of Contents

🚀 Features

  • Polymorphic Address model attachable to any Eloquent model via a trait
  • Lookup tables for Country and AdministrativeArea with seeders and migrations
  • Postal code normalization for US and Canada via (PostalCodeFormatter) with a clear, nullable contract
  • DB-backed AddressValidator to validate country, administrative area and postal codes
  • Service layer (AddressService) for create/update/delete/list operations
  • Soft deletes, UUID generation, and test coverage via Orchestra Testbench

📦 Installation

Install the package with Composer:

composer require blamodex/laravel-addresses

Publish the config file:

php artisan vendor:publish --tag=blamodex-address-config

Run the migrations:

php artisan migrate

⚙️ Configuration

Configuration lives in config/address.php (empty by default, but you can add options for formatting or validation):

return [
    // e.g. 'default_country' => 'CA'
];

🧩 Usage

1. Use the Addressable trait on models

For models that can have addresses:

use Blamodex\Address\Traits\Addressable;
use Blamodex\Address\Contracts\AddressableInterface;

class User extends Model implements AddressableInterface
{
    use Addressable;
}

2. Create an address

$user = User::find(1);

// Using the trait method
$address = $user->createAddress([
    'address_1' => '100 Main St',
    'city' => 'Anytown',
    'administrative_area_code' => 'CA',
    'postal_code' => '90001',
    'country_code' => 'US',
]);

// Or using the service directly
$service = app(\Blamodex\Address\Services\AddressService::class);
$address = $service->create($user, $attributes);

3. Update an address

$user->updateAddress($address, ['address_1' => '200 Main St']);

// Or via service
$service->update($address, ['address_1' => '200 Main St']);

4. Delete an address

$user->deleteAddress($address);

// Or via service
$service->delete($address);

5. Validation

Use the AddressValidator to check attributes before persisting:

$errors = \Blamodex\Address\Validators\AddressValidator::validate($attributes);
// Or throw on error
\Blamodex\Address\Validators\AddressValidator::validateOrFail($attributes);

PostalCodeFormatter::format() accepts ?string and returns ?stringnull indicates invalid or unsupported postal code.

🧪 Testing

This package uses Orchestra Testbench and PHPUnit.

Run tests:

composer test

Run tests with code coverage:

composer test:coverage

Check code style:

composer lint

Check code style and fix:

composer lint:fix

Check static analysis (phpstan) and tests as part of CI as configured in the repo.

📁 Project Structure

src/
├── Models/
│   ├── Address.php
│   ├── Country.php
│   └── AdministrativeArea.php
├── Services/
│   └── AddressService.php
├── Traits/
│   └── Addressable.php
├── Contracts/
│   └── AddressableInterface.php
├── Validators/
│   └── AddressValidator.php
├── Utils/
│   └── PostalCodeFormatter.php
├── config/
│   └── address.php
└── database/
    ├── migrations/
    └── seeders/

tests/
├── Unit/
│   ├── AddressServiceTest.php
│   ├── AddressTest.php
│   ├── AdministrativeAreaTest.php
│   ├── CountryTest.php
│   ├── PostalCodeFormatterTest.php
│   └── AddressValidatorTest.php
├── Fixtures/
│   ├── DummyAddressUser.php
│   └── DummyAddressCompany.php
└── TestCase.php

📄 License

MIT © Blamodex

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details.

🔗 Links

blamodex/laravel-addresses 适用场景与选型建议

blamodex/laravel-addresses 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 189 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「geocoding」 「address」 「laravel」 「location」 「country」 「addresses」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 blamodex/laravel-addresses 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 blamodex/laravel-addresses 我们能提供哪些服务?
定制开发 / 二次开发

基于 blamodex/laravel-addresses 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-08