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.
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')
]
];
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.
});
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
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email juststevemcd@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.