PHPackages                             charlielangridge/laravel-mail-previewer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. charlielangridge/laravel-mail-previewer

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

charlielangridge/laravel-mail-previewer
=======================================

Laravel Mail Previewer - allows you to preview mailables and notifications with data

v0.1.1(2mo ago)0653↓28.8%[2 PRs](https://github.com/charlielangridge/laravel-mail-previewer/pulls)1MITPHPPHP ^8.3CI passing

Since Feb 25Pushed 2mo agoCompare

[ Source](https://github.com/charlielangridge/laravel-mail-previewer)[ Packagist](https://packagist.org/packages/charlielangridge/laravel-mail-previewer)[ Docs](https://github.com/charlielangridge/laravel-mail-previewer)[ GitHub Sponsors](https://github.com/charlielangridge)[ RSS](/packages/charlielangridge-laravel-mail-previewer/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (3)Dependencies (26)Versions (6)Used By (1)

Laravel Mail Previewer
======================

[](#laravel-mail-previewer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/96ced8e9ccbb6c58bd62a950a2554f4e3ce2a1e28693ed865980a7e9fa3f01cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636861726c69656c616e6772696467652f6c61726176656c2d6d61696c2d7072657669657765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/charlielangridge/laravel-mail-previewer)[![GitHub Tests Action Status](https://camo.githubusercontent.com/7632b272eb6ac68f571b4ec6336651d609a155ec9c9c2498da205504f194f809/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636861726c69656c616e6772696467652f6c61726176656c2d6d61696c2d7072657669657765722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/charlielangridge/laravel-mail-previewer/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/118e3fdbca102eef01686badf1ce39d9690f993b0099295c9ffd00f800c74aaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636861726c69656c616e6772696467652f6c61726176656c2d6d61696c2d7072657669657765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/charlielangridge/laravel-mail-previewer)

Discover mailables and notifications in a Laravel app, inspect required inputs, and render preview HTML safely.

This package is designed for internal preview tooling and admin UIs.

Features
--------

[](#features)

- Discover all app mailables and notifications.
- Return structured metadata:
    - short `name`
    - full `class`
    - `subject` (including dynamic placeholder parsing)
    - `input_requirements`
- Resolve required constructor input for a selected class.
- For model-typed inputs, return up to 100 selectable DB options.
- Render HTML previews for mailables and notifications.
- Never sends email when rendering previews.

Requirements
------------

[](#requirements)

- PHP `^8.4`
- PHP `^8.3`
- Laravel `^11.0 || ^12.0`

Installation
------------

[](#installation)

```
composer require charlielangridge/laravel-mail-previewer
```

The package auto-registers via Laravel package discovery.

Quick Start
-----------

[](#quick-start)

```
use Charlielangridge\LaravelMailPreviewer\Facades\LaravelMailPreviewer;

$list = LaravelMailPreviewer::discover();

$requirements = LaravelMailPreviewer::inputRequirements(
    \App\Mail\FormCompletion::class
);

$issues = LaravelMailPreviewer::inputTypeHintingIssues();

$html = LaravelMailPreviewer::renderHtml(
    \App\Mail\FormCompletion::class,
    ['form' => 12]
);
```

API
---

[](#api)

### `LaravelMailPreviewer::discover(): array`

[](#laravelmailpreviewerdiscover-array)

Returns both mailables and notifications:

```
[
    'mailables' => [
        [
            'name' => 'FormCompletion',
            'class' => 'App\\Mail\\FormCompletion',
            'subject' => 'Hello **user->name**',
            'input_requirements' => [
                ['name' => 'form', 'type' => 'App\\Models\\Forms\\Form'],
            ],
        ],
    ],
    'notifications' => [
        // same shape
    ],
]
```

Subject extraction rules:

- Uses class-level default `subject` when available.
- Parses common subject definitions from class source:
    - `Envelope(subject: ...)`
    - `->subject(...)`
- Resolves local variables where possible:
    - `$subject = 'Test'; ->subject($subject)` becomes `Test`
- External/runtime references are converted to placeholders:
    - `'Hello '.$this->user->name` becomes `Hello **user->name**`

### `LaravelMailPreviewer::inputRequirements(string $className): array`

[](#laravelmailpreviewerinputrequirementsstring-classname-array)

Returns required constructor parameters for a mailable/notification.

If parameter type is an Eloquent model, includes `options` from DB (limit 100):

```
[
    [
        'name' => 'form',
        'type' => 'App\\Models\\Forms\\Form',
        'options' => [
            ['id' => 12, 'label' => 'Access Training Feedback'],
            // ...
        ],
    ],
    [
        'name' => 'token',
        'type' => 'string',
    ],
]
```

Notes:

- Non-model parameters do not include `options`.
- Unsupported classes return an empty array.

### `LaravelMailPreviewer::inputTypeHintingIssues(): array`

[](#laravelmailpreviewerinputtypehintingissues-array)

Returns mailables/notifications where required constructor inputs are not properly type-hinted (missing type hint or resolved as `mixed`), so you can work through and fix them.

```
[
    'mailables' => [
        [
            'kind' => 'mailable',
            'name' => 'FormCompletion',
            'class' => 'App\\Mail\\FormCompletion',
            'untyped_input_requirements' => [
                [
                    'name' => 'form',
                    'current_type' => 'mixed',
                    'has_type_hint' => false,
                    'suggested_type' => 'App\\Models\\Forms\\Form',
                    'suggestion_reason' => 'parameter name matches an app model class name',
                ],
            ],
        ],
    ],
    'notifications' => [
        // same shape
    ],
]
```

Suggestion strategy:

- Uses default parameter value type when present.
- Attempts to map parameter names to app model classes.
- Applies name heuristics (`...Id` =&gt; `int`, `is...` =&gt; `bool`, `token/email/name/...` =&gt; `string`).
- Falls back to `string`.

### `LaravelMailPreviewer::renderHtml(string $className, array $parameters = [], mixed $notifiable = null): ?string`

[](#laravelmailpreviewerrenderhtmlstring-classname-array-parameters---mixed-notifiable--null-string)

Renders HTML preview for a mailable or notification using Laravel's rendering pipeline.

```
$html = LaravelMailPreviewer::renderHtml(
    \App\Notifications\FormCompleted::class,
    ['form' => 12]
);
```

For model-typed constructor inputs, scalar values are treated as primary keys and resolved via `findOrFail`.

`$notifiable` is optional for notifications. If omitted, an internal anonymous notifiable is used.

Important:

- This method does not call send/notify pathways.
- It is for preview rendering only.

Tinker Examples
---------------

[](#tinker-examples)

```
use Charlielangridge\LaravelMailPreviewer\Facades\LaravelMailPreviewer;

// 1) list discoverable items
LaravelMailPreviewer::discover();

// 2) get inputs for chosen class
LaravelMailPreviewer::inputRequirements(\App\Mail\FormCompletion::class);

// 3) audit classes with weak constructor type hints
LaravelMailPreviewer::inputTypeHintingIssues();

// 4) render html preview with selected values
$html = LaravelMailPreviewer::renderHtml(
    \App\Mail\FormCompletion::class,
    ['form' => 12]
);

$html;
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for details.

License
-------

[](#license)

MIT. See [LICENSE.md](LICENSE.md).

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance85

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Total

3

Last Release

86d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4c3198a248b9580414af6bd9a09b66c8307b409de14b5bbec32140974323474?d=identicon)[charlielangridge](/maintainers/charlielangridge)

---

Top Contributors

[![charlielangridge](https://avatars.githubusercontent.com/u/8578083?v=4)](https://github.com/charlielangridge "charlielangridge (12 commits)")

---

Tags

laravelcharlielangridgelaravel-mail-previewer

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/charlielangridge-laravel-mail-previewer/health.svg)

```
[![Health](https://phpackages.com/badges/charlielangridge-laravel-mail-previewer/health.svg)](https://phpackages.com/packages/charlielangridge-laravel-mail-previewer)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M101](/packages/dedoc-scramble)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24857.5k](/packages/vormkracht10-laravel-mails)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
