statement = $statement; $this->filePath = $filePath; $this->isZip = $isZip; } /** * Build the message. * * @return $this */ public function build() { $subject = 'Your Account Statement'; if ($this->statement->is_period_range) { $subject .= " - {$this->statement->period_from} to {$this->statement->period_to}"; } else { $subject .= " - {$this->statement->period_from}"; } $email = $this->subject($subject) ->view('webstatement::statements.email') ->with([ 'statement' => $this->statement, 'accountNumber' => $this->statement->account_number, 'periodFrom' => $this->statement->period_from, 'periodTo' => $this->statement->period_to, 'isRange' => $this->statement->is_period_range, ]); if ($this->isZip) { $fileName = "{$this->statement->account_number}_{$this->statement->period_from}_to_{$this->statement->period_to}.zip"; $email->attach($this->filePath, [ 'as' => $fileName, 'mime' => 'application/zip', ]); } else { $fileName = "{$this->statement->account_number}_{$this->statement->period_from}.pdf"; $email->attach($this->filePath, [ 'as' => $fileName, 'mime' => 'application/pdf', ]); } return $email; } }