Support searching by client.id_number in the API

This commit is contained in:
Hillel Coren 2017-03-29 21:21:14 +03:00
parent 76c1b0efac
commit 6950ab8aa5
2 changed files with 4 additions and 2 deletions

View File

@ -46,11 +46,12 @@ class ClientApiController extends BaseAPIController
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')
->withTrashed(); ->withTrashed();
// Filter by email
if ($email = Input::get('email')) { if ($email = Input::get('email')) {
$clients = $clients->whereHas('contacts', function ($query) use ($email) { $clients = $clients->whereHas('contacts', function ($query) use ($email) {
$query->where('email', $email); $query->where('email', $email);
}); });
} elseif ($idNumber = Input::get('id_number')) {
$clients = $clients->whereIdNumber($idNumber);
} }
return $this->listResponse($clients); return $this->listResponse($clients);

View File

@ -25,11 +25,12 @@ For invoices, quotes, tasks and payments simply change the object type.
curl -X GET ninja.dev/api/v1/invoices -H "X-Ninja-Token: TOKEN" curl -X GET ninja.dev/api/v1/invoices -H "X-Ninja-Token: TOKEN"
You can search clients by their email address and invoices by their invoice number. You can search clients by their email address or id number and invoices by their invoice number.
.. code-block:: shell .. code-block:: shell
curl -X GET ninja.dev/api/v1/clients?email=<value> -H "X-Ninja-Token: TOKEN" curl -X GET ninja.dev/api/v1/clients?email=<value> -H "X-Ninja-Token: TOKEN"
curl -X GET ninja.dev/api/v1/clients?id_number=<value> -H "X-Ninja-Token: TOKEN"
curl -X GET ninja.dev/api/v1/invoices?invoice_number=<value> -H "X-Ninja-Token: TOKEN" curl -X GET ninja.dev/api/v1/invoices?invoice_number=<value> -H "X-Ninja-Token: TOKEN"
To load a single record specify the Id in the URL. To load a single record specify the Id in the URL.