承接 tor2r/laravel-bring-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tor2r/laravel-bring-api

最新稳定版本:v1.0.1

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.

统计信息

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

GitHub 信息

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

其他信息

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