icodestuff / laravel-mailwind
将 TailwindCSS 编译为 Laravel 可发送邮件
Requires
- php: ^8.0
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.13.0
- tijsverkoyen/css-to-inline-styles: ^2.2
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- spatie/laravel-ray: ^1.26
- dev-master
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.2.0
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- 0.1.0
- 0.0.2
- 0.0.1
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-5
- dev-dependabot/github_actions/actions/checkout-4
- dev-dependabot/github_actions/aglipanci/laravel-pint-action-2.3.0
- dev-dependabot/github_actions/ramsey/composer-install-2
This package is auto-updated.
Last update: 2024-09-09 04:22:10 UTC
README
关于 Laravel Mailwind
使用 TailwindCSS 设计您的 Laravel 可发送邮件,而不是依赖 markdown 或内联样式。 注意:在多个电子邮件客户端测试此包后,我遗憾地宣布它可能永远不会准备用于生产 😢
要求
- Laravel 9
- TailwindCSS
安装
您可以通过 composer 安装此包
composer require icodestuff/laravel-mailwind
您需要使用以下命令发布视图
php artisan vendor:publish --tag="mailwind-views"
入门
创建一个模板
默认情况下,Mailwind 导出名为 mailwind-example-template.blade.php
的示例模板。
如果您想创建一个新的模板,可以运行
php artisan mailwind:create MyTemplate
这将生成位于 resources/views/vendor/mailwind/templates
下的 my-template.blade.php
文件。
为了使用 Mailwind,您必须将新模板添加到
resources/views/vendor/mailwind/templates
。注意,我们目前不支持在templates/
文件夹中的子目录。
生成邮件视图
默认情况下,Mailwind 会检测您的电子邮件模板的更改,但如果您想重新生成所有视图,可以运行生成命令
php artisan mailwind:generate
这将生成位于 resources/views/vendor/mailwind/generated
目录下的编译视图。注意,所有生成的文件都会被 git 忽略,因此建议在部署脚本中运行 php artisan mailwind:generate
,类似于 npm run prod
。
准备您的邮件
通过运行
php artisan make:mail YourMailable
来生成新的 Laravel 邮件,然后通过实现 InteractsWithMailWind
特性将 Mailwind 与邮件相关联,如下所示
namespace App\Mail; use Icodestuff\Mailwind\Traits\InteractsWithMailWind; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; class YourMailable extends Mailable { use Queueable, SerializesModels, InteractsWithMailWind; }
然后在构建方法中,使用位于 resources/views/vendor/mailwind/templates
目录下的模板,如下所示
/** * Build the message. * * @return $this */ public function build() { return $this->view('mailwind::templates.my-template') // maps to: resources/views/vendor/mailwind/templates/my-template.blade.php ->subject('Mailwind Example Email'); }
发送邮件
运行 php artisan tinker
然后粘贴
Mail::to('test@example.com')->send(new App\Mail\YourMailable())
来发送您的电子邮件。如果您正在使用 Mailhog,您可以访问 https://:8025/ 来查看电子邮件:[点击查看邮件截图](https://rawcdn.githack.com/icodestuff-io/laravel-mailwind/HEAD/mailhog-screenshot.png)
测试
composer test
变更日志
请参阅 CHANGELOG 了解最近的变化。
致谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 获取更多信息。