Git Product home page Git Product logo

companies-house-laravel's Introduction

Laravel Companies House

Latest Version on Packagist Tests Total Downloads

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

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\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),
        ],
    ]
];

Usage

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.

Get A Company Profile

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')
        );
    }
}

Get A Companies Officers

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')
        );
    }
}

Get a specific Officer from a Company

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'),
        );
    }
}

Searching

There are a few options when it comes to searching, you can search for:

  • companies
  • officers
  • disqualified officers
  • search all

Searching for Companies

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
        );
    }
}

Searching for Officers

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
        );
    }
}

Searching everything

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
        );
    }
}

Validation

Using the validation inline:

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

Testing

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 [email protected] instead of using the issue tracker.

Credits

License

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

companies-house-laravel's People

Contributors

jeffcaulfield-morphsites avatar juststeveking avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

companies-house-laravel's Issues

Undefined index: sic_codes

Hello, thanks for working on this package. May you kindly assist. I am getting this error on Laravel 8 when i try to search company using company number

Undefined index: sic_codes {"userId":10,"exception":"[object] (ErrorException(code: 0): Undefined index: sic_codes at /home/vpn/Desktop/projects/sucasa/vendor/juststeveking/companies-house-laravel/src/Data/Company.php:93)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.