Skip to content

A Laravel wrapper to get companies house information and validate company numbers.

License

Notifications You must be signed in to change notification settings

JustSteveKing/companies-house-laravel

Repository files navigation

A Laravel wrapper to get companies house information and validate company numbers

Latest Version on Packagist Tests Total Downloads

A Laravel wrapper to get companies house information and validate company numbers. This is a work in progress and more methods will be added to the API as they are required.

This has been tested thoroughly in Laravel 8, Laravel 7 is supported but if you find issues please do drop a detailed issue.

Installation

You can install the package via composer:

composer require juststeveking/companies-house-laravel

You can publish the config file with:

php artisan vendor:publish --provider="JustSteveKing\CompaniesHouseLaravel\CompaniesHouseLaravelServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    'api' => [
        'key' => env('COMPANIES_HOUSE_KEY', ''),
        'url' => env('COMPANIES_HOUSE_URL', 'https://api.companieshouse.gov.uk')
    ]
];

Usage

Using it inline:

use JustSteveKing\CompaniesHouseLaravel\Client;

// Make a new client
$api = Client::make();

// Get Company information from a company number
$company = $api->company('company-number');

Using the validation inline:

$this->validate($request, [
    'company_number' => [
        'required',
        'string',
        Rule::companyNumber()
    ]
]);

Searching for a company by name, please note this will return an empty collection if there are no results:

use JustSteveKing\CompaniesHouseLaravel\Client;

$api = Client::make();

// Get a collection of Company\SearchResult inside of a CompanyCollection
$results = $api->searchCompany('Name you want to search');

// You now have access to all standard Laravel collection methods
$results->each(function ($result) {
    // Do something with the result here.
});

Fetching a Collection of Company Officers will return an OfficerCollection:

use JustSteveKing\CompaniesHouseLaravel\Client;

$api = Client::make();

// Get a collection of Company\SearchResult inside of a CompanyCollection
$results = $api->getOfficers('company-number');

// You now have access to all standard Laravel collection methods
$results->each(function ($result) {
    // Do something with the result here.
});

Testing

Using this library in your own tests

There is a relatively simple testing utility on this library, that allows you to fake the underlying Http client:

use Illuminate\Support\Facades\Http
use JustSteveKing\CompaniesHouseLaravel\Client;

$fakedApi = Client::fake([
    'https://api.companieshouse.gov.uk/*',
    Http::response([], 200, [])
]);

To understand how to use this part please follow the Laravel documentation for Testing the Http Client

Run the unit tests:

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email juststevemcd@gmail.com instead of using the issue tracker.

Credits

License

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

About

A Laravel wrapper to get companies house information and validate company numbers.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Languages