user = $user; $this->booking = $booking; $this->file = $file; } public function toMail() { $mailMessage = (new MailMessage)->subject('Transfer Completed (REF: ' . $this->booking->marking . ')'); // 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); // } // } // 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($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; } }