From d032ae00fcea7e60a2afc42b33a04ad5a68ca948 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 6 Jun 2016 19:04:24 +0300 Subject: [PATCH] Added support for searching by invoice number in the API --- app/Http/Requests/InvoiceRequest.php | 16 +++++++++++++--- app/Ninja/Transformers/EntityTransformer.php | 10 +++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/Http/Requests/InvoiceRequest.php b/app/Http/Requests/InvoiceRequest.php index 5e2d931390..edf43203c6 100644 --- a/app/Http/Requests/InvoiceRequest.php +++ b/app/Http/Requests/InvoiceRequest.php @@ -1,5 +1,7 @@ invoice_number && ! $invoice) { + $invoice = Invoice::scope() + ->whereInvoiceNumber($this->invoice_number) + ->withTrashed() + ->firstOrFail(); + } + // eager load the invoice items if ($invoice && ! $invoice->relationLoaded('invoice_items')) { $invoice->load('invoice_items'); } - + return $invoice; } -} \ No newline at end of file +} diff --git a/app/Ninja/Transformers/EntityTransformer.php b/app/Ninja/Transformers/EntityTransformer.php index d2d02bd0b6..691e6ff67f 100644 --- a/app/Ninja/Transformers/EntityTransformer.php +++ b/app/Ninja/Transformers/EntityTransformer.php @@ -38,23 +38,23 @@ class EntityTransformer extends TransformerAbstract { return $date ? $date->getTimestamp() : null; } - + public function getDefaultIncludes() { return $this->defaultIncludes; } - + protected function getDefaults($entity) { $data = [ 'account_key' => $this->account->account_key, - 'is_owner' => (bool) Auth::user()->owns($entity), + 'is_owner' => (bool) (Auth::check() && Auth::user()->owns($entity)), ]; - + if ($entity->relationLoaded('user')) { $data['user_id'] = (int) $entity->user->public_id + 1; } - + return $data; } }