PHP code example of tor2r / laravel-bring-api
1. Go to this page and download the library: Download tor2r/laravel-bring-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tor2r / laravel-bring-api example snippets
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'),
];
use Tor2r\BringApi\Facades\BringApi;
$city = BringApi::postalCodeGetCity('8445'); // Default $countryCode = 'no'
// Returns: "Melbu"
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',
// ]
// ]
// ]
use Tor2r\BringApi\BringApi;
class MyController
{
public function show(BringApi $bringApi, string $postalCode)
{
$city = $bringApi->postalCodeGetCity($postalCode);
return response()->json(['city' => $city]);
}
}
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
}
bash
php artisan vendor:publish --tag="bring-api-config"