allow attaching uploaded files when sending mails
This commit is contained in:
		| @@ -35,10 +35,17 @@ class Invoice extends Notification | ||||
|      */ | ||||
|     public $attach_pdf; | ||||
|  | ||||
|     /** | ||||
|      * List of document attachments to attach when sending the email. | ||||
|      * | ||||
|      * @var array | ||||
|      */ | ||||
|     public $attachments; | ||||
|  | ||||
|     /** | ||||
|      * Create a notification instance. | ||||
|      */ | ||||
|     public function __construct(Document $invoice = null, string $template_alias = null, bool $attach_pdf = false, array $custom_mail = []) | ||||
|     public function __construct(Document $invoice = null, string $template_alias = null, bool $attach_pdf = false, array $custom_mail = [], $attachments = []) | ||||
|     { | ||||
|         parent::__construct(); | ||||
|  | ||||
| @@ -46,6 +53,7 @@ class Invoice extends Notification | ||||
|         $this->template = EmailTemplate::alias($template_alias)->first(); | ||||
|         $this->attach_pdf = $attach_pdf; | ||||
|         $this->custom_mail = $custom_mail; | ||||
|         $this->attachments = $attachments; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -68,6 +76,17 @@ class Invoice extends Notification | ||||
|             ]); | ||||
|         } | ||||
|  | ||||
|         // Attach selected attachments | ||||
|         if (! empty($this->invoice->attachment)) { | ||||
|             foreach ($this->invoice->attachment as $attachment) { | ||||
|                 if (in_array($attachment->id, $this->attachments)) { | ||||
|                     $message->attach($attachment->getAbsolutePath(), [ | ||||
|                         'mime' => $attachment->mime_type, | ||||
|                     ]); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         return $message; | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user