user = $user; $this->packingList = $packingList; } public function toMail() { $invoice = $this->packingList->transactions()->where('type', TransactionType::SHIPPING_INVOICE)->where('status', ApprovalStatus::APPROVED)->first(); $invoiceDocument = $invoice->documents()->first()->files; $mailMessage = (new MailMessage) ->subject('Att: '.$this->user->name.' - Invoice for order no.'. $this->packingList->owner->reference); $filesystemDriver = Storage::getDefaultDriver(); $filename = $invoiceDocument->first()->file->file_info->original->file; Log::info('ShipmentDepartureEmail file name: '.$filename); if($filesystemDriver === 's3'){ $fileContent = null; $fileContent = Storage::disk('s3')->get($filename); 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/' . $filename); if ($filePath) { $mailMessage->attach($filePath, [ 'as' => 'invoice.pdf', 'mime' => 'application/pdf', ]); } } Log::info('InvoiceIssuedEmail sent - Att: '.$this->user->name.' - Invoice for order no.'. $this->packingList->owner->reference); $mailMessage->view('emails.shipment.invoice', ['user' => $this->user, 'packingList' => $this->packingList]); return $mailMessage; } }