One of the most valuable features of Ray is its ability to preview emails in your local environment.
In this post, we'll explore how Ray can help you preview emails in your local environment and how it can simplify the process of developing and testing email workflows in Laravel.
Rendering a mailable in Ray
To use Ray in a Laravel app, you only need to install the
laravel-ray package. Changes are that, as a Ray user, you've already done this.
composer require spatie/laravel-ray
After that, there's no configuration needed. Whenever your Laravel app will now send a mailable, it will be displayed in Ray. Here's how that looks.
How does this work behind the scenes? Laravel is configured to write all emails to the log in a local environment. This prevents mails from being sent accidentally. Ray listens to what is writing in the log, and when it detects mail, it will pick up on it and display it.
Testing email workflows in Ray
The mail displayed in Ray isn't static: all the links of the displayed mail will just work. This makes it easy to test entire email workflows using Ray.
A typical web app has a password reset flow where you get a mail that contains a link to reset your password. Using Ray, you can quickly test out the entire flow.
This technique doesn't only work for a password reset but for any email flow in your app.
Ray makes testing emails in a Laravel app very easy. There are lots more niceties for debugging Laravel apps in Ray. It can display all events, executed SQL queries, sent HTTP requests, and much more. Learn all about it our extensive documentation for Laravel.