Skip to content

Instantly share code, notes, and snippets.

@deselbi
Last active June 6, 2017 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deselbi/593b516a5acb7580a0236601218784dd to your computer and use it in GitHub Desktop.
Save deselbi/593b516a5acb7580a0236601218784dd to your computer and use it in GitHub Desktop.
Laravel queued mailable with pdf attachement
<?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