Added support for searching by invoice number in the API
This commit is contained in:
parent
d5cb8b3abe
commit
d032ae00fc
2 changed files with 18 additions and 8 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php namespace App\Http\Requests;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
class InvoiceRequest extends EntityRequest {
|
||||
|
||||
protected $entityType = ENTITY_INVOICE;
|
||||
|
|
@ -7,13 +9,21 @@ class InvoiceRequest extends EntityRequest {
|
|||
public function 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
|
||||
if ($invoice && ! $invoice->relationLoaded('invoice_items')) {
|
||||
$invoice->load('invoice_items');
|
||||
}
|
||||
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue