charlielangridge/filament-mail-previewer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

charlielangridge/filament-mail-previewer

Composer 安装命令:

composer require charlielangridge/filament-mail-previewer

包简介

Filament Mail Previewer - allows you to preview mailables and notifications in Filament

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Filament Mail Previewer adds a Filament page that discovers your app mailables and notifications, asks for any required constructor inputs, and renders the email HTML side-by-side in desktop and mobile frames.

It uses charlielangridge/laravel-mail-previewer under the hood to discover classes and render previews.

Requirements

  • PHP ^8.3
  • Laravel app with Filament ^5.0
  • A Filament panel where you can register plugins

Installation

Install the package:

composer require charlielangridge/filament-mail-previewer

The package auto-discovers its service provider.

Register The Plugin In Your Filament Panel

Add the plugin to your panel provider (example: app/Providers/Filament/AdminPanelProvider.php):

use CharlieLangridge\FilamentMailPreviewer\FilamentMailPreviewerPlugin;
use Filament\Panel;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugins([
            FilamentMailPreviewerPlugin::make(),
        ]);
}

This registers:

  • a navigation page: Mail Previewer
  • a preview page used after selecting a mailable/notification

Filament Theme Setup (Important)

If you are using a custom Filament theme, include this package's Blade files in your Tailwind content sources so page styles/classes are picked up:

@source '../../../../vendor/charlielangridge/filament-mail-previewer/resources/**/*.blade.php';

Then rebuild your assets.

If you have not created a custom Filament theme yet, follow the Filament docs first:

Optional Configuration

Publish config if you want to override the facade class used to talk to the underlying Laravel mail previewer package:

php artisan vendor:publish --tag="filament-mail-previewer-config"

Published config:

return [
    'laravel_mail_previewer_facade' => \Charlielangridge\LaravelMailPreviewer\Facades\LaravelMailPreviewer::class,
    'authorization' => [
        'mode' => 'none',
        'gate_ability' => 'viewFilamentMailPreviewer',
        'policy' => [
            'model' => null,
            'ability' => 'viewAny',
        ],
        'callback' => null,
    ],
];

In most apps you do not need to change this.

Authorization (Optional)

By default, access is open to users who can access your panel (authorization.mode = none).

You can restrict the plugin using one of the following approaches.

Gate-based authorization

Set:

'authorization' => [
    'mode' => 'gate',
    'gate_ability' => 'viewFilamentMailPreviewer',
],

Then define the gate in your app (example in AuthServiceProvider):

Gate::define('viewFilamentMailPreviewer', fn (User $user): bool => $user->is_admin);

Policy-based authorization

Set:

'authorization' => [
    'mode' => 'policy',
    'policy' => [
        'model' => \App\Support\MailPreviewerAccess::class,
        'ability' => 'viewAny',
    ],
],

Then register a policy for that model and implement the ability:

class MailPreviewerAccessPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->is_admin;
    }
}

Callback authorization

Use a config callback:

'authorization' => [
    'callback' => fn (?Authenticatable $user): bool => (bool) $user?->is_admin,
],

Or define it directly in your panel plugin registration:

FilamentMailPreviewerPlugin::make()
    ->authorizeUsing(fn (?Authenticatable $user): bool => (bool) $user?->is_admin);

When a callback is set, it takes precedence over mode.

Usage

  1. Open your Filament panel.
  2. Go to Mail Previewer in navigation.
  3. Select a mailable or notification row and click Preview.
  4. Fill required inputs in the modal.
  5. Submit to open the rendered email preview page.

The preview page shows:

  • desktop frame
  • mobile frame
  • heading + resolved subject

How Inputs Are Handled

The plugin automatically builds a form from discovered constructor/input requirements:

  • model inputs become searchable selects
  • array inputs are entered as JSON
  • integer inputs are numeric fields
  • fields with date in the name become date pickers
  • other values are captured in textareas

For notifications, a notifiable model input is added automatically when possible (usually defaults to the authenticated user in the modal).

Troubleshooting

If the table is empty or you see the install notice:

  • ensure charlielangridge/laravel-mail-previewer is installed (it is a dependency of this plugin)
  • ensure your mailables/notifications are discoverable in your app
  • clear caches and reload:
php artisan optimize:clear

Testing

composer test

Changelog

See CHANGELOG.md.

Contributing

See .github/CONTRIBUTING.md.

Security

See .github/SECURITY.md.

Credits

License

MIT. See LICENSE.md.

统计信息

  • 总下载量: 539
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固