2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
2016-05-01 21:30:39 +02:00
|
|
|
|
2016-06-06 18:04:24 +02:00
|
|
|
use App\Models\Invoice;
|
|
|
|
|
2017-01-30 17:05:31 +01:00
|
|
|
class InvoiceRequest extends EntityRequest
|
|
|
|
{
|
2016-05-01 21:30:39 +02:00
|
|
|
protected $entityType = ENTITY_INVOICE;
|
|
|
|
|
|
|
|
public function entity()
|
|
|
|
{
|
2016-05-01 22:55:13 +02:00
|
|
|
$invoice = parent::entity();
|
2016-06-06 18:04:24 +02:00
|
|
|
|
|
|
|
// support loading an invoice by its invoice number
|
|
|
|
if ($this->invoice_number && ! $invoice) {
|
|
|
|
$invoice = Invoice::scope()
|
|
|
|
->whereInvoiceNumber($this->invoice_number)
|
|
|
|
->withTrashed()
|
2017-03-20 12:56:24 +01:00
|
|
|
->first();
|
|
|
|
|
|
|
|
if (! $invoice) {
|
|
|
|
abort(404);
|
|
|
|
}
|
2016-06-06 18:04:24 +02:00
|
|
|
}
|
|
|
|
|
2016-05-05 09:15:51 +02:00
|
|
|
// eager load the invoice items
|
|
|
|
if ($invoice && ! $invoice->relationLoaded('invoice_items')) {
|
2016-05-01 22:55:13 +02:00
|
|
|
$invoice->load('invoice_items');
|
2016-05-01 21:30:39 +02:00
|
|
|
}
|
2016-06-06 18:04:24 +02:00
|
|
|
|
2016-05-01 22:55:13 +02:00
|
|
|
return $invoice;
|
2016-05-01 21:30:39 +02:00
|
|
|
}
|
2016-06-06 18:04:24 +02:00
|
|
|
}
|