
Laravel can do that?
Matt Stauffer has a new post outlining four things he didn’t know Laravel could do, but learned about them while writing his new book, Laravel: up and running.
The four items he outlines is:
- The Cookie Façade is one special cookie
- Attaching files to emails is easier than you think
- You can chain more Scheduler methods than the docs show
- You can assert that a view gets passed certain data
While I was reading through this I started thinking about the email attachments and how ->attach
expects a real file. It seems like you should be able to pass it raw data and still attach files easily.
Just as you might imagine Laravel does support this through ->attachData
. Here is an example:
Mail::send('emails.whitepaper', [], function ($m) use($pdf) {
$m->to('barasa@wangusi.ke');
$m->subject('Your whitepaper download');
$m->attachData($pdf->generate($data), 'filename.pdf');
});
As long as $pdf->generate($data)
in my sample returns the raw bytes, it’ll be attached without having to first save it to the filesystem. For more on this see the documentation.
Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.
Laravel Jobs

- Software Developer
-
Remote (US & Canada)
Alley - 😎 Laravel Developer
-
Remote
Jogg, Inc - Junior, Mid, and Senior Software Engineers. Laravel / Vue. Saint Petersburg, FL
-
Saint Petersburg, FL and Remote
ShineOn - Senior PHP Developer (Laravel)
-
Remote
The Interaction Design Foundation - Fullstack Laravel Engineer (Munich/Remote) 💻
-
Munich, Germany or Remote
AirLST GmbH
Laravel Angular Admin Starter Kit
Laravel Angular Admin is an administration dashboard starter kit designed to give you a base to start working with. I…
A look at what’s coming to Laravel 5.3
Laravel 5.3 is now released and available for everyone. Here is a quick look at some of these new features: Laravel S…