خرید بک لینک

Vote count: 0

How would one create an 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']);
        });
}

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 25 فروردين 1395 ساعت: 5:17

صفحه بندی