A Laravel wrapper to get companies house information and validate company numbers.
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\CompaniesHouse\CompaniesHouseServiceProvider" --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.company-information.service.gov.uk'),
'timeout' => env('COMPANIES_HOUSE_TIMEOUT', 10),
'retry' => [
'times' => env('COMPANIES_HOUSE_RETRY_TIMES', null),
'milliseconds' => env('COMPANIES_HOUSE_RETRY_MILLISECONDS', null),
],
]
];
This library is aimed to be easy to use, and slots into Laravel with no issues.
The package will install a Service Provider for you, meaning that all you need to do is resolve the Client
from the container, and start using it.
To get a company profile, you can quite simply:
use JustSteveKing\CompaniesHouse\Client;
class CompanyController extends Controler
{
public function __construct(
protected Client $service,
) {}
public function __invoke(Request $request)
{
$company = $this->service->company(
companyNumber: $request->get('company_number')
);
}
}
You can get a Collection
of Company Officers using the companies number:
use JustSteveKing\CompaniesHouse\Client;
class CompanyOfficersController extends Controler
{
public function __construct(
protected Client $service,
) {}
public function __invoke(Request $request)
{
$company = $this->service->officers(
companyNumber: $request->get('company_number')
);
}
}
You can get an Officer
from a company using the company number and their appointment ID:
use JustSteveKing\CompaniesHouse\Client;
class CompanyOfficerController extends Controler
{
public function __construct(
protected Client $service,
) {}
public function __invoke(Request $request)
{
$company = $this->service->officer(
companyNumber: $request->get('company_number'),
appointmentId: $request->get('appointment_id'),
);
}
}
There are a few options when it comes to searching, you can search for:
- companies
- officers
- disqualified officers
- search all
This will return a SearchCollection
use JustSteveKing\CompaniesHouse\Client;
class CompanySearchController extends Controler
{
public function __construct(
protected Client $service,
) {}
public function __invoke(Request $request)
{
$results = $this->service->searchCompany(
query: $request->get('query'),
perPage: 25, //optional
startIndex: 0, //optional
);
}
}
This will return a SearchCollection
use JustSteveKing\CompaniesHouse\Client;
class OfficersSearchController extends Controler
{
public function __construct(
protected Client $service,
) {}
public function __invoke(Request $request)
{
$results = $this->service->searchOfficers(
query: $request->get('query'),
perPage: 25, //optional
startIndex: 0, //optional
);
}
}
This will return a SearchCollection
use JustSteveKing\CompaniesHouse\Client;
class SearchController extends Controler
{
public function __construct(
protected Client $service,
) {}
public function __invoke(Request $request)
{
$results = $this->service->search(
query: $request->get('query'),
perPage: 25, //optional
startIndex: 0, //optional
);
}
}
Using the validation inline:
$this->validate($request, [
'company_number' => [
'required',
'string',
Rule::companyNumber()
]
]);
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.