Laravel Markdown



May 19, 2020 A quick visual reference on the latest Laravel mail markdown components. Note: I’m using Laravel 7 at the time of writing this article. Source code: Quick Start. LaRecipe is a code-driven package created by Saleem Hadad that provides an easy way to create beautiful documentation for your product or application inside your Laravel app using Markdown. To get started in your project, you need to install it via composer and run the setup command to publish the necessary assets and configuration.

The most concise screencasts for the working developer, updated daily. There's no shortage of content at Laracasts. In fact, you could watch nonstop for days upon days, and still not see everything! Since the messages are written in Markdown, Laravel is able to render beautiful, responsive HTML templates for the messages while also automatically generating a plain-text counterpart.

Preview your notifications easily with just a couple of lines of code

Sometimes you want to develop beautiful notifications in HTML or markdown format. But how do you style them easily without having to send them every time you've changed something? Laravel offers an out of the box solution for this. In your web.php you can easily return a notification to render it and display it in your web browser.

Let's code!

Markdown

If you'd like to try this with an easy example you can code along with me. First, we start with creating an example notification:

$ php artisan make:notification InvoicePaid

Secondly, we add the following lines to our web.php to be able to display the notification in our browser:

As the title of this article might confuse, it sounds like we render a Notification, in this case, InvoicePaid. But what we're actually rendering here is the MailMessage we return in the toMail method.

Laravel

Rendering markdown notifications

Laravel supports sending markdown notifications as well and it would be nice to be able to preview these as well in the browser. For this kind of notifications it requires a little bit more code:

In this case, we use the IlluminateMailMarkdown class to render the markdown to HTML. Go to /notification in your browser to see if it works!

(Bonus!) Rendering On-Demand Notifications

All objects which are using the Notifiable trait can be notified through their desired channel. This is a great out of the box feature from Laravel. But there are times that you'd like to send a notification to an email or mobile number which isn't a Notifiable instance (yet). Laravel calls these On-Demand Notifications. To render On-Demand Notifications in your browser we have the following workaround:

Laravel Markdown

Laravel Markdown Table

Laravel markdown tutorial

Laravel Markdown Free

In the background, Laravel uses the AnonymousNotifiable class to send notifications on-demand.