領収証発行サービス
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

43 linhas
1.1KB

  1. <?php
  2. namespace App\Events\Email;
  3. use App\Email\BaseEmailer;
  4. use App\Models\Email;
  5. use App\Models\EmailAttachment;
  6. use Illuminate\Broadcasting\InteractsWithSockets;
  7. use Illuminate\Database\Eloquent\Collection;
  8. use Illuminate\Foundation\Events\Dispatchable;
  9. use Illuminate\Queue\SerializesModels;
  10. class ConfirmEvent
  11. {
  12. use Dispatchable, InteractsWithSockets, SerializesModels;
  13. public Email $email;
  14. /**
  15. * Create a new event instance.
  16. *
  17. * @return void
  18. */
  19. public function __construct(Email|BaseEmailer $email, ?Collection $attachments = null)
  20. {
  21. if ($email instanceof Email) {
  22. $this->email = $email;
  23. } else {
  24. $this->email = $email->makeModel();
  25. $this->email->save();
  26. }
  27. if ($attachments !== null) {
  28. foreach ($attachments as $attachment) {
  29. if (!($attachment instanceof EmailAttachment)) continue;
  30. $emailId = $this->email->id;
  31. $attachment->email_id = $emailId;
  32. $attachment->save();
  33. }
  34. }
  35. }
  36. }