Inspect and Develop Mail Templates with Laravel Mailbook

  • Reading time ~ 3 min
  • 20.01.2023
Laravel Mailbook is a package that lets you quickly inspect your mail templates without triggering them in your application.

Laravel Mailbook is a package that lets you quickly inspect your mail templates without triggering them in your application. Given that the mail is rendered in a browser, it allows you to quickly tweak styles, text, and localization without having to fire a mailable over and over again:

This package works by installing it via composer and then running the provided mailbook:install command to set up a routes/mailbook.php route file where you can register emails.

// routes/mailbook.php
// This will use dependency injection if your mailable has parameters
Mailbook::add(VerificationMail::class);

// Use a closure to customize the parameters of the mail instance
Mailbook::add(function (): VerificationMail {
    $user = User::factory()->make();

    return new VerificationMail($user, '/example/url')
});

One of the coolest features I noticed when checking out this package is Variants, which you can use to provide multiple scenarios for the same mailable or notification:

// routes/mailbook.php
// Use a closure to customize the parameters of the mail instance
Mailbook::add(OrderCreatedMail::class)
    ->variant('1 item', function () {
        return new OrderCreatedMail(
            Order::factory()->withOneProduct()->create()
        );
    })
    ->variant('2 items', function () {
        return new OrderCreatedMail(
            Order::factory()->withTwoProducts()->create()
        );
    });

At the time of writing, Mailbook provides the following features to improve your workflow for working with mailables:

  • Configure different variants using the same mailable
  • Database usage with automatic rollback
  • Localization support to quickly view mailables in other languages
  • Quickly toggle between various size breakpoints
  • Explore all mailables from the UI's left navigation menu

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Original
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

I'm full stack laravel developer

I knew my call in programming back in 2006.

WORK EXPERIENCE
CONTACT
Ukraine, Lutsk
+380979856297