-
-
Notifications
You must be signed in to change notification settings - Fork 636
Expand file tree
/
Copy pathInvoiceRepository.php
More file actions
45 lines (37 loc) · 1.15 KB
/
InvoiceRepository.php
File metadata and controls
45 lines (37 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace HiEvents\Repository\Eloquent;
use HiEvents\DomainObjects\InvoiceDomainObject;
use HiEvents\Models\Invoice;
use HiEvents\Repository\Interfaces\InvoiceRepositoryInterface;
/**
* @extends BaseRepository<InvoiceDomainObject>
*/
class InvoiceRepository extends BaseRepository implements InvoiceRepositoryInterface
{
protected function getModel(): string
{
return Invoice::class;
}
public function getDomainObject(): string
{
return InvoiceDomainObject::class;
}
public function findLatestInvoiceForEvent(int $eventId): ?InvoiceDomainObject
{
$invoice = $this->model
->whereHas('order', function ($query) use ($eventId) {
$query->where('event_id', $eventId);
})
->orderBy('id', 'desc')
->first();
return $this->handleSingleResult($invoice);
}
public function findLatestInvoiceForOrder(int $orderId): ?InvoiceDomainObject
{
$invoice = $this->model
->where('order_id', $orderId)
->orderBy('id', 'desc')
->first();
return $this->handleSingleResult($invoice);
}
}