You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InvoiceObserver.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Observers;
  3. use App\Models\Accounting\DocumentLineItem;
  4. use App\Models\Accounting\Invoice;
  5. use App\Models\Accounting\Transaction;
  6. use Illuminate\Support\Facades\DB;
  7. class InvoiceObserver
  8. {
  9. /**
  10. * Handle the Invoice "created" event.
  11. */
  12. public function created(Invoice $invoice): void
  13. {
  14. //
  15. }
  16. /**
  17. * Handle the Invoice "updated" event.
  18. */
  19. public function updated(Invoice $invoice): void
  20. {
  21. //
  22. }
  23. public function deleting(Invoice $invoice): void
  24. {
  25. //
  26. }
  27. /**
  28. * Handle the Invoice "deleted" event.
  29. */
  30. public function deleted(Invoice $invoice): void
  31. {
  32. DB::transaction(function () use ($invoice) {
  33. $invoice->lineItems()->each(function (DocumentLineItem $lineItem) {
  34. $lineItem->delete();
  35. });
  36. $invoice->transactions()->each(function (Transaction $transaction) {
  37. $transaction->delete();
  38. });
  39. });
  40. }
  41. /**
  42. * Handle the Invoice "restored" event.
  43. */
  44. public function restored(Invoice $invoice): void
  45. {
  46. //
  47. }
  48. /**
  49. * Handle the Invoice "force deleted" event.
  50. */
  51. public function forceDeleted(Invoice $invoice): void
  52. {
  53. //
  54. }
  55. }