Added support for searching by invoice number in the API

This commit is contained in:
Hillel Coren 2016-06-06 19:04:24 +03:00
parent d5cb8b3abe
commit d032ae00fc
2 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,7 @@
<?php namespace App\Http\Requests; <?php namespace App\Http\Requests;
use App\Models\Invoice;
class InvoiceRequest extends EntityRequest { class InvoiceRequest extends EntityRequest {
protected $entityType = ENTITY_INVOICE; protected $entityType = ENTITY_INVOICE;
@ -8,6 +10,14 @@ class InvoiceRequest extends EntityRequest {
{ {
$invoice = parent::entity(); $invoice = parent::entity();
// support loading an invoice by its invoice number
if ($this->invoice_number && ! $invoice) {
$invoice = Invoice::scope()
->whereInvoiceNumber($this->invoice_number)
->withTrashed()
->firstOrFail();
}
// eager load the invoice items // eager load the invoice items
if ($invoice && ! $invoice->relationLoaded('invoice_items')) { if ($invoice && ! $invoice->relationLoaded('invoice_items')) {
$invoice->load('invoice_items'); $invoice->load('invoice_items');

View File

@ -48,7 +48,7 @@ class EntityTransformer extends TransformerAbstract
{ {
$data = [ $data = [
'account_key' => $this->account->account_key, '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')) { if ($entity->relationLoaded('user')) {