定制 tor2r/laravel-bring-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

tor2r/laravel-bring-api

Composer 安装命令:

composer require tor2r/laravel-bring-api

包简介

Fetch adresses and postal codes from Bring (no) API

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel package for interacting with the Bring API. Fetch postal code information and addresses for Norwegian locations.

Supports Laravel 11, 12 and 13.

Supported Countries

  • NO - Norway (default)
  • DK - Denmark
  • SE - Sweden
  • FI - Finland
  • NL - Netherlands
  • DE - Germany
  • US - United States
  • BE - Belgium
  • FO - Faroe Islands
  • GL - Greenland
  • IS - Iceland
  • SJ - Svalbard and Jan Mayen

Installation

You can install the package via composer:

composer require tor2r/laravel-bring-api

You can publish the config file with:

php artisan vendor:publish --tag="bring-api-config"

Configuration

Add the following environment variables to your .env file:

BRING_API_UID=your-mybring-email@example.com
BRING_API_KEY=your-api-key

You can get your API credentials by registering at Mybring and generating an API key in your account settings.

The published config file (config/bring-api.php) contains:

return [
    'uid' => env('BRING_API_UID'),
    'key' => env('BRING_API_KEY'),
    'base_url' => env('BRING_API_BASE_URL', 'https://api.bring.com/address'),
    'default_countrycode' => env('BRING_API_DEFAULT_COUNTRYCODE', 'no'),
];

Usage

Using the Facade

Get city name for a postal code

use Tor2r\BringApi\Facades\BringApi;

$city = BringApi::postalCodeGetCity('8445'); // Default $countryCode = 'no'
// Returns: "Melbu"

Get full postal code information

use Tor2r\BringApi\Facades\BringApi;

$data = BringApi::postalCode('1555');
// Returns an array with postal code details:
// [
//     'postal_codes' => [
//         [
//             'city' => 'Son',
//             'postal_code' => '1555',
//             'postal_code_type' => 'STREET_ADDRESSES',
//             'municipality' => 'Vestby',
//             'municipalityId' => '3019',
//             'county' => 'Akershus',
//             'latitude' => '59.5237',
//             'longitude' => '10.6862',
//         ]
//     ]
// ]

Using Dependency Injection

use Tor2r\BringApi\BringApi;

class MyController
{
    public function show(BringApi $bringApi, string $postalCode)
    {
        $city = $bringApi->postalCodeGetCity($postalCode);

        return response()->json(['city' => $city]);
    }
}

Error Handling

The package throws Tor2r\BringApi\Exceptions\BringApiException when something goes wrong. Norwegian postal codes must be exactly 4 digits.

use Tor2r\BringApi\Facades\BringApi;
use Tor2r\BringApi\Exceptions\BringApiException;

try {
    $city = BringApi::postalCodeGetCity('0000'); // Non-existent postal code
} catch (BringApiException $e) {
    // API error response
}

Available Methods

Method Description Returns
postalCode(string $postalCode, string $countryCode = 'no') Get full postal code data from Bring API array
postalCodeGetCity(string $postalCode, string $countryCode = 'no') Get only the city name for a postal code ?string

Response Fields

The postalCode() method returns an array containing a postal_codes key with the following fields per entry:

Field Type Description
postal_code string The postal code
city string City name
municipality string Municipality name
municipalityId string Municipality ID
county string County name
postal_code_type string One of: STREET_ADDRESSES, PO_BOX, COMBINED, SPECIAL_SERVICE
latitude string Latitude (WGS84)
longitude string Longitude (WGS84)

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

tor2r/laravel-bring-api 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-12