- How do I install Mailbook in a Laravel project?
- Run `composer require --dev xammie/mailbook` to install the package, then execute `php artisan mailbook:install` to generate the `routes/mailbook.php` file. This file is where you register your mailables or notifications for previewing.
- Can I preview Laravel notifications (not just mailables) with Mailbook?
- Yes, Mailbook supports both Laravel mailables and notifications. Simply register them in `routes/mailbook.php` using `Mailbook::add(YourNotification::class)` or a closure to customize parameters.
- Does Mailbook work with Laravel 9 or older versions?
- Mailbook officially supports Laravel 10–13. While Laravel 9 may work with minor adjustments, the package is actively developed for newer Laravel versions, and some features (like dependency injection) may require manual tweaks.
- How do I register a mailer with dynamic data (e.g., factory models) in Mailbook?
- Use a closure in `routes/mailbook.php` to generate dynamic data. For example, `Mailbook::add(function () { return new VerificationMail(User::factory()->make()); })` injects a factory model into your mailer before previewing.
- Will Mailbook interfere with my production email sends?
- No, Mailbook is designed for development only. It registers a `/mailbook` route that should be excluded from production or protected with middleware (e.g., `auth:sanctum`). It never triggers real email sends.
- Can I customize the preview UI or styling of Mailbook?
- Yes, Mailbook publishes customizable views and config files. Run `php artisan vendor:publish --tag=mailbook-views` to override the default Tailwind CSS styling or modify the preview layout in `resources/views/vendor/mailbook/`.
- How does Mailbook handle queued mailables (ShouldQueue) for testing?
- Mailbook bypasses queues by default. For queued mailables, ensure your `ShouldQueue` logic is compatible with Mailbook’s preview mode. If issues arise, check the [GitHub issue tracker](https://github.com/Xammie/mailbook/issues) for fixes like v1.8.4’s queue handling improvements.
- Does Mailbook support localization (e.g., multi-language emails)?
- Yes, Mailbook respects Laravel’s localization system. Register variants for different locales in `routes/mailbook.php` using closures or pass locale-specific parameters to your mailables.
- What if I get a route conflict with `/mailbook` in my Laravel app?
- Mailbook installs a `/mailbook` route by default. If this conflicts with your existing routes, rename it in `routes/mailbook.php` or exclude it from production using middleware like `Route::middleware(['web', 'auth:sanctum'])->group(...);`.
- Are there alternatives to Mailbook for previewing Laravel emails?
- Alternatives include manually testing emails in a staging environment or using packages like `spatie/laravel-mail-preview` (for simpler setups). However, Mailbook stands out with dependency injection, closures, and built-in UI for dynamic previews without extra configuration.