Support setting country in API using country code

This commit is contained in:
Hillel Coren 2017-06-15 10:24:40 +03:00
parent 8ba71ce6ce
commit cb533871ac
2 changed files with 12 additions and 0 deletions

View File

@ -149,6 +149,7 @@ class InvoiceApiController extends BaseAPIController
'country_id',
'private_notes',
'currency_code',
'country_code',
] as $field) {
if (isset($data[$field])) {
$clientData[$field] = $data[$field];

View File

@ -106,6 +106,17 @@ class ClientRepository extends BaseRepository
}
}
// convert country code to id
if (isset($data['country_code'])) {
$countryCode = strtolower($data['country_code']);
$country = Cache::get('countries')->filter(function ($item) use ($countryCode) {
return strtolower($item->iso_3166_2) == $countryCode || strtolower($item->iso_3166_3) == $countryCode;
})->first();
if ($country) {
$data['country_id'] = $country->id;
}
}
$client->fill($data);
$client->save();