Laravel0Inspect and Develop Mail Templates with Laravel Mailbook

[ad_1]

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.

[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *