Php

I'm handling billing, creating invoices and all myself. what's the best way to determine if the invoice due for a particular subscription has been created?

Hello everyone, I'm building a subscriptions platform and I'm not using stripe. I'm handling billing, creating invoices and all myself. I wanted to ask a question, what's the best way to determine if the invoice due for a particular subscription has been created? Right now, all i'm using is a local scope on the Invoice model to check
 
 public function scopeHasInvoiceBeenCreatedAlready($query, $subscription)
{
if ($subscription->invoices()->count() > 0) {
$collection = $query->where('subscription_id', $subscription->id)
->whereDate('created_at', '>=', $subscription->invoice_due_date)
->whereNotNull('sent_at')
->where('paid', false)
->latest()
->get();

if ($collection->isNotEmpty()) {
return true;
}
}

return false;
}

 
I'll sincerely appreciate any one that has a better approach to go about this.
You already invited:

If you wanna answer this question please Login or Register