Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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. DB::transaction(function () use ($invoice) {
  26. $invoice->lineItems()->each(function (DocumentLineItem $lineItem) {
  27. $lineItem->delete();
  28. });
  29. $invoice->transactions()->each(function (Transaction $transaction) {
  30. $transaction->delete();
  31. });
  32. });
  33. }
  34. /**
  35. * Handle the Invoice "deleted" event.
  36. */
  37. public function deleted(Invoice $invoice): void
  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. }