diff --git a/app/Http/Requests/InvoiceRequest.php b/app/Http/Requests/InvoiceRequest.php index 5e2d93139003..edf43203c695 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 d2d02bd0b6ee..691e6ff67f20 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; } }