Download the PHP package pxlrbt/laravel-notification-preview without Composer
On this page you can find all versions of the php package pxlrbt/laravel-notification-preview. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pxlrbt/laravel-notification-preview
More information about pxlrbt/laravel-notification-preview
Files in pxlrbt/laravel-notification-preview
Package laravel-notification-preview
Short Description Browse, preview and test-send every notification and mailable in your Laravel app – mail as HTML and text, other channels as their payload.
License MIT
Informations about the package laravel-notification-preview
Laravel Notification Preview
Browse, preview and test-send every notification and mailable in your Laravel app.
Features
- Discovers every notification and mailable in the directories you point it at.
- Builds each one for you; supply your own data with resolvers and named variants.
- Renders the HTML and the plain-text side of a mail, at desktop, tablet and mobile widths.
- Shows every other channel as the JSON payload it would hand its provider.
- Switches locale, edits scalar arguments in place and sends a real test mail to any address.
- Never registers its routes in production; gate it anywhere else with an auth closure.
Installation
The routes register themselves and are always disabled in the production
environment. Open the preview at /dev/notifications.
Configuration
paths takes directories only — namespaces come from Composer's PSR-4 map. Point
it at a whole domain directory if you like; abstract classes and anything that is
neither a notification nor a mailable are skipped.
Both mailable styles work: envelope()/content() and the older build().
Other channels
Mail is the only channel rendered as a message. Every other one is shown as the JSON payload it would hand its provider. Opt them in:
Each notification gains one tab per channel its via() declares. Names match
driver strings and channel classes alike, so smsapi also covers an
SmsapiChannel::class.
Authorization
By default there is no check: outside production, anybody who can reach the URL can open the preview. Narrow that down with an auth closure:
Anyone the closure turns down gets a 403.
Hiding classes
exclude takes fully qualified class names and namespaces. A namespace hides
everything below it:
Argument resolution
For each constructor parameter the preview tries these sources, in order, and takes the first one that answers:
| # | Source | Applies to |
|---|---|---|
| 1 | A value edited in the UI | Scalars, enums and dates |
| 2 | A registered resolver | The parameter reference first, then its type |
| 3 | The parameter's default value | Anything with a default |
| 4 | A value derived from the type | See below |
| 5 | A faked scalar derived from the parameter name | $email, $url, $name and $*Id get plausible values, everything else gets 'Sample text' |
Step 4 derives from the type itself:
| Type | Value |
|---|---|
| Enum | Its first case |
| Date | now() |
| Model | Model::factory()->make(), falling back to Model::query()->first() |
| Collection | Empty |
| Anything else | Resolved from the container |
Supplying your own data
Resolvers
Register these in a service provider, keyed by type:
Untyped parameters cannot be matched by type, so key them by parameter instead. A key registered against a parent class covers every subclass:
The notifiable that notifications are rendered against works the same way:
Per-notification configuration
for() returns one object holding everything the viewer shows about a single
notification — its label, its group and its variants:
Variants are for notifications that need more than constructor arguments — setters, a specific state, a particular payload. A variant returns the finished notification and skips argument resolution entirely.
Labels are derived when you do not set them: from the class name for the
notification, from its key for a variant, so by-customer shows as
"By Customer". label() and group() both take a string or a closure, and a
closure defers a translation until the preview is rendered rather than resolving
it while your service provider boots:
Variants can pin their own notifiable:
Configuration on the notification itself
To keep the preview data next to the notification, add a static preview()
method. Same object, no interface to implement:
Both sources merge, and anything registered through for() wins — per property,
and per variant key. A class that declares a label and a service provider that
sets only a group end up with both.
Registering and excluding classes
Testing
All versions of laravel-notification-preview with dependencies
composer-runtime-api Version ^2.0
illuminate/contracts Version ^11.0|^12.0
spatie/laravel-package-tools Version ^1.16