Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

1.1 KB
Raw Blame
<?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);
    }
}