From 6df19923e988999831b830cf1f0673a572a7e5c8 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sat, 25 May 2024 01:48:05 +0800 Subject: [PATCH] Laravel Vapor - test attaching a file in an email + upload file to S3 (code sync from shipping portal) --- .../PaymentProofUploadedEmail.php | 57 +++++++++++++------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/app/Classes/Notifications/PaymentProofUploadedEmail.php b/app/Classes/Notifications/PaymentProofUploadedEmail.php index c2307d76..26cd3fd6 100644 --- a/app/Classes/Notifications/PaymentProofUploadedEmail.php +++ b/app/Classes/Notifications/PaymentProofUploadedEmail.php @@ -36,26 +36,47 @@ class PaymentProofUploadedEmail extends AbstractEmail public function toMail() { - $attachedFile = null; - $file_info = $this->file->getFileAttribute($this->file)->file->file_info; - foreach ($file_info as $fileCount => $fileVal) { - if (isset($fileVal->original)) { - $file_path = $fileVal->original->file; + $mailMessage = (new MailMessage)->subject('Transfer Completed (REF: ' . $this->booking->marking . ')'); - // $filesystemDriver = Storage::getDefaultDriver(); - // if($filesystemDriver === 's3'){ - // $fileContent = Storage::disk('s3')->get('documents/'.$file_path); - // } - // else{ - // $attachedFile = storage_path('app/documents/' . $file_path); - // } - } - } + // STEP 1: Get file to be attached to email + // $attachedFile = null; + // $file_path = ''; + // $file_info = $this->file->getFileAttribute($this->file)->file->file_info; + // foreach ($file_info as $fileCount => $fileVal) { + // if (isset($fileVal->original)) { + // $file_path = $fileVal->original->file; + // //$attachedFile = storage_path('app/documents/' . $file_path); + // } + // } - return (new MailMessage) - ->subject('Transfer Completed (REF: ' . $this->booking->marking . ')') - // ->attach($attachedFile) // todo-new: add attachement - ->view('emails.accounts.payment_proof_email', ['user' => $this->user, 'booking' => $this->booking]); + // STEP 2: Check whether to fetch from S3 bucket or local storage + // if($file_path){ + // $filesystemDriver = Storage::getDefaultDriver(); + // if($filesystemDriver === 's3'){ + // $fileContent = null; + // $fileContent = Storage::disk('s3')->get('documents/' . $file_path); + // if ($fileContent) { + // $mailMessage->attachData($fileContent, 'invoice.pdf', [ + // 'mime' => 'application/pdf', + // ]); + // } + // } + // else{ + // $filePath = ''; + // // $fileContent = Storage::disk('documents')->get($invoiceDocument->first()->file->file_info->original->file); + // $filePath = storage_path('app/documents/' . $file_path); + // if ($filePath) { + // $mailMessage->attach($filePath, [ + // 'as' => 'invoice.pdf', + // 'mime' => 'application/pdf', + // ]); + // } + // } + // } + + $mailMessage->view('emails.accounts.payment_proof_email', ['user' => $this->user, 'booking' => $this->booking]); + + return $mailMessage; }