Create optional message parts to Laravel's Mail function?
E.g. either adding attachment or having bcc.
Mail::send('emails.welcome', $data, function($message)
{
$message->from('us@example.com', 'Laravel');
$message->to('foo@example.com')->cc('bar@example.com');
$message->attach($pathToFile); <========= OPTIONAL =========
});
I REALLY want to avoid ugly code like this
if (isset($data['attachment'])) {
// Attachment
Mail::queue('emails.raw', ['content' => $content], function($message) use ($data) {
$message
->subject($data['subject'])
->attach($data['attachment'])
->to($data['email'])
->bcc($data['bcc']);
});
}
else{
// No attachment
Mail::queue('emails.raw', ['content' => $content], function($message) use ($data) {
$message
->subject($data['subject'])
->to($data['email'])
->bcc($data['bcc']);
});
}