Add all files
This commit is contained in:
58
app/Observers/InvoiceObserver.php
Normal file
58
app/Observers/InvoiceObserver.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Events\Invoice as InvoiceEvent;
|
||||
use App\Models\Invoice;
|
||||
|
||||
class InvoiceObserver
|
||||
{
|
||||
/**
|
||||
* Handle the Invoice "creating" event.
|
||||
*/
|
||||
public function creating(Invoice $invoice): void
|
||||
{
|
||||
event(new InvoiceEvent\Creating($invoice));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Invoice "created" event.
|
||||
*/
|
||||
public function created(Invoice $invoice): void
|
||||
{
|
||||
event(new InvoiceEvent\Created($invoice));
|
||||
|
||||
$sendEmail = $invoice->send_create_email;
|
||||
|
||||
dispatch(function () use ($invoice, $sendEmail) {
|
||||
event(new InvoiceEvent\Finalized($invoice, $sendEmail));
|
||||
})->afterResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Invoice "updating" event.
|
||||
*/
|
||||
public function updating(Invoice $invoice): void
|
||||
{
|
||||
event(new InvoiceEvent\Updating($invoice));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Invoice "updated" event.
|
||||
*/
|
||||
public function updated(Invoice $invoice): void
|
||||
{
|
||||
if ($invoice->isDirty('status') && $invoice->status == 'paid') {
|
||||
event(new InvoiceEvent\Paid($invoice));
|
||||
}
|
||||
event(new InvoiceEvent\Updated($invoice));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the Invoice "deleted" event.
|
||||
*/
|
||||
public function deleted(Invoice $invoice): void
|
||||
{
|
||||
event(new InvoiceEvent\Deleted($invoice));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user