rendering mailables

This commit is contained in:
Taylor Otwell 2018-02-13 07:45:35 -06:00
parent fa9202dd5f
commit be3b1d7e31
1 changed files with 22 additions and 12 deletions

34
mail.md
View File

@ -14,9 +14,10 @@
- [Generating Markdown Mailables](#generating-markdown-mailables)
- [Writing Markdown Messages](#writing-markdown-messages)
- [Customizing The Components](#customizing-the-components)
- [Previewing Mailables In The Browser](#previewing-mailables-in-the-browser)
- [Sending Mail](#sending-mail)
- [Queueing Mail](#queueing-mail)
- [Rendering Mailables](#rendering-mailables)
- [Previewing Mailables In The Browser](#previewing-mailables-in-the-browser)
- [Mail & Local Development](#mail-and-local-development)
- [Events](#events)
@ -419,17 +420,6 @@ After exporting the components, the `resources/views/vendor/mail/html/themes` di
> {tip} If you would like to build an entirely new theme for the Markdown components, write a new CSS file within the `html/themes` directory and change the `theme` option of your `mail` configuration file.
<a name="previewing-mailables-in-the-browser"></a>
## Previewing Mailables In The Browser
When designing a mailable's template, it is convenient to quickly preview the rendered mailable in your browser like a typical Blade template. For this reason, Laravel allows you to return any mailable directly from a route Closure or controller. When a mailable is returned, it will be rendered and displayed in the browser, allowing you to quickly preview its design without needing to send it to an actual email address:
Route::get('/mailable', function () {
$invoice = App\Invoice::find(1);
return new App\Mail\InvoicePaid($invoice);
});
<a name="sending-mail"></a>
## Sending Mail
@ -471,6 +461,26 @@ Of course, you are not limited to just specifying the "to" recipients when sendi
->bcc($evenMoreUsers)
->send(new OrderShipped($order));
<a name="rendering-mailables"></a>
## Rendering Mailables
Sometimes you may wish to capture the HTML content of a mailable without sending it. To accomplish this, you may call the `render` method of the mailable. This method will return the evaluated contents of the mailable as a string:
$invoice = App\Invoice::find(1);
return (new App\Mail\InvoicePaid($invoice))->render();
<a name="previewing-mailables-in-the-browser"></a>
### Previewing Mailables In The Browser
When designing a mailable's template, it is convenient to quickly preview the rendered mailable in your browser like a typical Blade template. For this reason, Laravel allows you to return any mailable directly from a route Closure or controller. When a mailable is returned, it will be rendered and displayed in the browser, allowing you to quickly preview its design without needing to send it to an actual email address:
Route::get('/mailable', function () {
$invoice = App\Invoice::find(1);
return new App\Mail\InvoicePaid($invoice);
});
<a name="queueing-mail"></a>
### Queueing Mail