Added support for currency_code in API

This commit is contained in:
Hillel Coren 2016-02-29 12:01:43 +02:00
parent 16da4fcbfe
commit f4fd45118c

View File

@ -1,6 +1,7 @@
<?php namespace App\Ninja\Repositories;
use DB;
use Cache;
use App\Ninja\Repositories\BaseRepository;
use App\Models\Client;
use App\Models\Contact;
@ -74,6 +75,17 @@ class ClientRepository extends BaseRepository
$client = Client::scope($publicId)->with('contacts')->firstOrFail();
}
// convert currency code to id
if (isset($data['currency_code'])) {
$currencyCode = strtolower($data['currency_code']);
$currency = Cache::get('currencies')->filter(function($item) use ($currencyCode) {
return strtolower($item->code) == $currencyCode;
})->first();
if ($currency) {
$data['currency_id'] = $currency->id;
}
}
$client->fill($data);
$client->save();