Created
November 23, 2017 16:06
-
-
Save OSDDQD/63a540e775bbe2c8145321d95b3be91c to your computer and use it in GitHub Desktop.
Sending queued email
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\Jobs; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Queue\SerializesModels; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use Illuminate\Foundation\Bus\Dispatchable; | |
use App\Models\Invoice; | |
class SendInvoice implements ShouldQueue | |
{ | |
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | |
protected $invoice; | |
public function __construct(Invoice $invoice) | |
{ | |
$this->invoice = $invoice; | |
} | |
/** | |
* Execute the job. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
$pdf = \App::make('dompdf.wrapper'); | |
$html = view('site.partial.invoice', [ | |
'invoice' => $this->invoice | |
])->render(); | |
$pdf->loadHTML($html); | |
$pdf->save(storage_path("invoices/invoice_{$this->invoice->id}.pdf")); | |
\Mail::send('site.email.invoice', [], function($message) { | |
$message->from(env('MAIL_USERNAME'), 'Cottonfair'); | |
$message->to($this->invoice->email)->subject(trans('site.invoice.subject')); | |
$message->attach(storage_path("invoices/invoice_{$this->invoice->id}.pdf"), [ | |
'as' => 'invoice.pdf', | |
'mime' => 'application/pdf', | |
]); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment