Last active
June 6, 2017 13:15
-
-
Save deselbi/593b516a5acb7580a0236601218784dd to your computer and use it in GitHub Desktop.
Laravel queued mailable with pdf attachement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Mail; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Mail\Mailable; | |
use Illuminate\Queue\SerializesModels; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
/** | |
* Usage: | |
* | |
* Mail::to('test@example.com')->send(new HasPdfAttachment($pdf)); | |
*/ | |
class HasPdfAttachment extends Mailable implements ShouldQueue | |
{ | |
use Queueable, SerializesModels; | |
protected $pdf; | |
public function __construct($pdf) | |
{ | |
$this->pdf = base64_encode($pdf); | |
} | |
public function build() | |
{ | |
return $this->view('emails.layout') | |
->attachData(base64_decode($this->pdf), 'document.pdf', [ | |
'mime' => 'application/pdf', | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment