File: D:/HostingSpaces/SBogers10/werkenbij.komma.pro/app/Mail/ApplyMail.php
<?php
namespace App\Mail;
use App\Komma\Composers\ApplyFormComposer;
use App\Komma\Documents\Kms\DocumentService;
use App\Komma\Documents\Kms\DocumentServiceInterface;
use App\Komma\Documents\Models\Document;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class ApplyMail extends Mailable
{
use Queueable, SerializesModels;
protected $request;
/**
* @var DocumentServiceInterface
*/
private $documentService;
/**
* @var \Illuminate\Support\Collection
*/
private $documents;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($request)
{
$this->request = $request;
$this->documentService = app(DocumentServiceInterface::class);
$this->setDocuments();
// Textarea should be converted with nl2br
if(isset($this->request['form_message'])) $this->request['form_message'] = nl2br($this->request['form_message']);
}
/**
* Retrieves the uploaded documents.
*/
private function setDocuments()
{
$documentsAttribute = ApplyFormComposer::documentsAttribute();
$this->documents = $this->documentService->getDocumentsUsingAttributeKey($documentsAttribute->getKey());
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
//Remember: The documents will be deleted automatically by the housekeeper via the documentService. No need to delete them here.
//Attach the uploaded documents to the mail
foreach($this->documents as $document)
{
/** @var Document $document */
$filePath = public_path($document->file_system_path);
if(file_exists($filePath)) $this->attach($filePath);
}
return $this->view('emails.contact')
->subject(trans('site/email.contact.subject'))
->to(config('site.mailTo'))
->with(['request' => $this->request]);
}
}