PHP code example of tor2r / laravel-brreg-api

1. Go to this page and download the library: Download tor2r/laravel-brreg-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-brreg-api example snippets


return [
    'base_url' => env('BRREG_API_BASE_URL', 'https://data.brreg.no'),
    'results_per_page' => env('BRREG_API_RESULTS_PER_PAGE', 100),
];

use Tor2r\BrregApi\Facades\BrregApi;

// Fetch a single entity by organisation number
$entity = BrregApi::getByOrgnr('987654321');

// Search by name
$results = BrregApi::searchByName('Sesam');

// Limit the number of results
$results = BrregApi::searchByName('Sesam', 10);

// Fetch a single voluntary organisation
$org = BrregApi::voluntary()->getByOrgnr('987654321');

// Search voluntary organisations by name
$results = BrregApi::voluntary()->searchByName('Frivillig');

$entity = BrregApi::getByOrgnr('925183873');

// [
//     'organisasjonsnummer' => '925183873',
//     'navn' => 'FAGFOKUS AS',
//     'organisasjonsform' => [...],
//     'forretningsadresse' => [...],
//     'antallAnsatte' => 7,
//     ...
// ]

$results = BrregApi::searchByName('Fagfokus');

// [
//     'data' => [
//         [
//             'organisasjonsnummer' => '925183873',
//             'navn' => 'FAGFOKUS AS',
//             'antallAnsatte' => 7,
//             ...
//         ],
//     ],
//     'meta' => [
//         'per_page' => 100,
//         'total' => 1,
//         'total_pages' => 1,
//         'current_page' => 0,
//     ],
// ]

use Tor2r\BrregApi\Exceptions\BrregApiException;

try {
    $entity = BrregApi::getByOrgnr('000000000');
} catch (BrregApiException $e) {
    // "No entity found with organisation number: 000000000"
    echo $e->getMessage();
}
bash
php artisan vendor:publish --tag="brreg-api-config"