You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# A Laravel wrapper to get companies house information and validate company numbers
8
-
9
9
[](https://packagist.org/packages/juststeveking/companies-house-laravel)
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.
15
-
16
-
This has been tested thoroughly in Laravel 8, Laravel 7 is supported but if you find issues please do drop a detailed issue.
14
+
A Laravel wrapper to get companies house information and validate company numbers.
This library is aimed to be easy to use, and slots into Laravel with no issues.
45
48
46
-
```php
47
-
use JustSteveKing\CompaniesHouseLaravel\Client;
49
+
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.
48
50
49
-
// Make a new client
50
-
$api = Client::make();
51
51
52
-
// Get Company information from a company number
53
-
$company = $api->company('company-number');
54
-
```
52
+
### Get A Company Profile
55
53
56
-
Using the validation inline:
54
+
To get a company profile, you can quite simply:
57
55
58
56
```php
59
-
$this->validate($request, [
60
-
'company_number' => [
61
-
'required',
62
-
'string',
63
-
Rule::companyNumber()
64
-
]
65
-
]);
57
+
use JustSteveKing\CompaniesHouse\Client;
58
+
59
+
class CompanyController extends Controler
60
+
{
61
+
public function __construct(
62
+
protected Client $service,
63
+
) {}
64
+
65
+
public function __invoke(Request $request)
66
+
{
67
+
$company = $this->service->company(
68
+
companyNumber: $request->get('company_number')
69
+
);
70
+
}
71
+
}
66
72
```
67
73
68
-
Searching for a company by name, please note this will return an empty collection if there are no results:
74
+
75
+
## Get A Companies Officers
76
+
77
+
You can get a `Collection` of Company Officers using the companies number:
69
78
70
79
```php
71
-
use JustSteveKing\CompaniesHouseLaravel\Client;
80
+
use JustSteveKing\CompaniesHouse\Client;
81
+
82
+
class CompanyOfficersController extends Controler
83
+
{
84
+
public function __construct(
85
+
protected Client $service,
86
+
) {}
87
+
88
+
public function __invoke(Request $request)
89
+
{
90
+
$company = $this->service->officers(
91
+
companyNumber: $request->get('company_number')
92
+
);
93
+
}
94
+
}
95
+
```
96
+
72
97
73
-
$api = Client::make();
98
+
### Get a specific Officer from a Company
74
99
75
-
// Get a collection of Company\SearchResult inside of a CompanyCollection
76
-
$results = $api->searchCompany('Name you want to search');
100
+
You can get an `Officer` from a company using the company number and their appointment ID:
77
101
78
-
// You now have access to all standard Laravel collection methods
79
-
$results->each(function ($result) {
80
-
// Do something with the result here.
81
-
});
102
+
```php
103
+
use JustSteveKing\CompaniesHouse\Client;
104
+
105
+
class CompanyOfficerController extends Controler
106
+
{
107
+
public function __construct(
108
+
protected Client $service,
109
+
) {}
110
+
111
+
public function __invoke(Request $request)
112
+
{
113
+
$company = $this->service->officer(
114
+
companyNumber: $request->get('company_number'),
115
+
appointmentId: $request->get('appointment_id'),
116
+
);
117
+
}
118
+
}
82
119
```
83
120
84
-
Fetching a Collection of Company Officers will return an OfficerCollection:
85
121
86
-
```php
87
-
use JustSteveKing\CompaniesHouseLaravel\Client;
122
+
### Searching
123
+
124
+
There are a few options when it comes to searching, you can search for:
125
+
126
+
- companies
127
+
- officers
128
+
- disqualified officers
129
+
- search all
130
+
88
131
89
-
$api = Client::make();
132
+
#### Searching for Companies
90
133
91
-
// Get a collection of Company\SearchResult inside of a CompanyCollection
92
-
$results = $api->getOfficers('company-number');
134
+
This will return a `SearchCollection`
93
135
94
-
// You now have access to all standard Laravel collection methods
95
-
$results->each(function ($result) {
96
-
// Do something with the result here.
97
-
});
136
+
```php
137
+
use JustSteveKing\CompaniesHouse\Client;
138
+
139
+
class CompanySearchController extends Controler
140
+
{
141
+
public function __construct(
142
+
protected Client $service,
143
+
) {}
144
+
145
+
public function __invoke(Request $request)
146
+
{
147
+
$results = $this->service->searchCompany(
148
+
query: $request->get('query'),
149
+
perPage: 25, //optional
150
+
startIndex: 0, //optional
151
+
);
152
+
}
153
+
}
98
154
```
99
155
100
156
101
-
## Testing
157
+
#### Searching for Officers
158
+
159
+
This will return a `SearchCollection`
160
+
161
+
```php
162
+
use JustSteveKing\CompaniesHouse\Client;
163
+
164
+
class OfficersSearchController extends Controler
165
+
{
166
+
public function __construct(
167
+
protected Client $service,
168
+
) {}
169
+
170
+
public function __invoke(Request $request)
171
+
{
172
+
$results = $this->service->searchOfficers(
173
+
query: $request->get('query'),
174
+
perPage: 25, //optional
175
+
startIndex: 0, //optional
176
+
);
177
+
}
178
+
}
179
+
```
102
180
103
-
### Using this library in your own tests
104
181
105
-
There is a relatively simple testing utility on this library, that allows you to fake the underlying Http client:
182
+
#### Searching everything
183
+
184
+
This will return a `SearchCollection`
106
185
107
186
```php
108
-
use Illuminate\Support\Facades\Http
109
-
use JustSteveKing\CompaniesHouseLaravel\Client;
187
+
use JustSteveKing\CompaniesHouse\Client;
188
+
189
+
class SearchController extends Controler
190
+
{
191
+
public function __construct(
192
+
protected Client $service,
193
+
) {}
194
+
195
+
public function __invoke(Request $request)
196
+
{
197
+
$results = $this->service->search(
198
+
query: $request->get('query'),
199
+
perPage: 25, //optional
200
+
startIndex: 0, //optional
201
+
);
202
+
}
203
+
}
204
+
```
205
+
206
+
## Validation
207
+
208
+
Using the validation inline:
110
209
111
-
$fakedApi = Client::fake([
112
-
'https://api.companieshouse.gov.uk/*',
113
-
Http::response([], 200, [])
210
+
```php
211
+
$this->validate($request, [
212
+
'company_number' => [
213
+
'required',
214
+
'string',
215
+
Rule::companyNumber()
216
+
]
114
217
]);
115
218
```
116
219
220
+
221
+
## Testing
222
+
117
223
To understand how to use this part please follow the Laravel documentation for [Testing the Http Client](https://laravel.com/docs/8.x/http-client#testing)
0 commit comments