### Install Mailbook Package via Composer Source: https://github.com/xammie/mailbook/blob/main/README.md Installs the Mailbook package as a development dependency using Composer. ```bash composer require --dev xammie/mailbook ``` -------------------------------- ### Run Mailbook Installation Command Source: https://github.com/xammie/mailbook/blob/main/README.md Executes the artisan command to install Mailbook into the Laravel application, typically creating the mailbook route file. ```bash php artisan mailbook:install ``` -------------------------------- ### Registering Mailable with Database Rollback (PHP) Source: https://github.com/xammie/mailbook/blob/main/README.md Example of registering a mailable with Mailbook, demonstrating how database changes made within the closure (e.g., creating models with factories) are automatically rolled back after the mail is rendered. ```php // All database changes are rolled back after rendering the mail. Mailbook::add(function (): OrderShippedMail { $order = Order::factory()->create(); $tracker = Tracker::factory()->create(); return new OrderShippedMail($order, $tracker); }); ``` -------------------------------- ### Running Mailbook Tests (Bash) Source: https://github.com/xammie/mailbook/blob/main/README.md Execute the test suite for the Mailbook package using Composer. ```bash composer test ``` -------------------------------- ### Publishing Mailbook Views (Bash) Source: https://github.com/xammie/mailbook/blob/main/README.md Publish the default Mailbook views to your application's resources directory, allowing you to customize the UI. ```bash php artisan vendor:publish --tag="mailbook-views" ``` -------------------------------- ### Publishing Mailbook Configuration File (Bash) Source: https://github.com/xammie/mailbook/blob/main/README.md Publish the default Mailbook configuration file to your application's config directory, allowing you to customize its settings. ```bash php artisan vendor:publish --tag="mailbook-config" ``` -------------------------------- ### Register Mailables with Dependency Injection Source: https://github.com/xammie/mailbook/blob/main/README.md Illustrates how to use dependency injection within the registration closure, either automatically via type hinting or manually resolving from the container. ```php // With dependency injection Mailbook::add(function (VerificationService $verificationService): VerificationMail { return new VerificationMail($verificationService, '/example/url'); }); // Without dependency injection Mailbook::add(function (): VerificationMail { $verificationService = app(VerificationService::class); return new VerificationMail($verificationService, '/example/url'); }); ``` -------------------------------- ### Register Mailables in Mailbook Routes Source: https://github.com/xammie/mailbook/blob/main/README.md Demonstrates two methods to register mailables: directly referencing the class (using DI) or using a closure for custom instantiation and parameter passing. ```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'); }); ``` -------------------------------- ### Register Mailables and Notifications Source: https://github.com/xammie/mailbook/blob/main/README.md Shows how to register both standard Laravel Mailables and Notification classes with Mailbook. ```php // Mailable Mailbook::add(VerificationMail::class); // Notification Mailbook::add(InvoiceCreatedNotification::class); ``` -------------------------------- ### Define Mailable Variants Source: https://github.com/xammie/mailbook/blob/main/README.md Creates different preview variants for a single mailable class, allowing testing of various scenarios (e.g., different data states) using the `variant()` method. ```php // Use a closure to customize the parameters of the mail instance Mailbook::add(OrderCreatedMail::class) ->variant('1 item', fn () => new OrderCreatedMail(Order::factory()->withOneProduct()->create())) ->variant('2 items', fn () => new OrderCreatedMail(Order::factory()->withTwoProducts()->create())); ``` -------------------------------- ### Configure Mailbook Locales Source: https://github.com/xammie/mailbook/blob/main/README.md Adds available locales to the Mailbook configuration file (`mailbook.php`) to enable language switching for mail previews. ```php 'locales' => [ 'en' => 'English', 'nl' => 'Dutch', 'de' => 'German', 'es' => 'Spanish' ], ``` -------------------------------- ### Register Notification for Specific User Source: https://github.com/xammie/mailbook/blob/main/README.md Registers a notification to be previewed as if sent to a specific user instance (notifiable) using the `to()` method. ```php $user = User::factory()->create(); Mailbook::to($user)->add(WelcomeNotification::class); ``` -------------------------------- ### Register Notification for Specific Email Source: https://github.com/xammie/mailbook/blob/main/README.md Registers a notification to be previewed as if sent to a specific email address using the `to()` method. ```php Mailbook::to('example@mailbook.dev')->add(WelcomeNotification::class); ``` -------------------------------- ### Configuring Mail Sending in Mailbook (PHP) Source: https://github.com/xammie/mailbook/blob/main/README.md Enable and configure the mail sending feature in Mailbook, which adds a button to send the currently selected mail to a specified email address using the default mail driver. ```php 'send' => true, 'send_to' => 'test@mailbook.dev', ``` -------------------------------- ### Enabling Database Rollback in Mailbook Configuration (PHP) Source: https://github.com/xammie/mailbook/blob/main/README.md Configure Mailbook to automatically rollback database changes after rendering mailables, allowing safe use of factories and queries during development. ```php 'database_rollback' => true, ``` -------------------------------- ### Group Mailables by Category Source: https://github.com/xammie/mailbook/blob/main/README.md Organizes multiple mailables or notifications under a common category using the `category()` and `group()` methods for better organization in the Mailbook UI. ```php Mailbook::category('Invoices')->group(function () { Mailbook::add(InvoiceCreatedNotification::class); Mailbook::add(InvoicePaidNotification::class); }); ``` -------------------------------- ### Group Mailables by Category and Recipient Source: https://github.com/xammie/mailbook/blob/main/README.md Combines grouping by category and applying a default recipient to a set of mailables or notifications. ```php Mailbook::to('example@mailbook.dev') ->category('Invoices') ->group(function () { // ... }); ``` -------------------------------- ### Group Mailables with Default Recipient Source: https://github.com/xammie/mailbook/blob/main/README.md Applies a default recipient (user or email) to all mailables or notifications registered within a group using the `to()` and `group()` methods. ```php Mailbook::to('example@mailbook.dev')->group(function () { Mailbook::add(WelcomeNotification::class); Mailbook::add(TrialEndedNotification::class); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.