tomirons / tuxedo
Laravel 5.4 mailables 的简单事务性电子邮件类/模板
v2.0.0
2021-02-26 00:46 UTC
Requires
- php: ^7.3
- illuminate/database: ^6.0|^7.0|^8.0
- illuminate/mail: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.2
This package is not auto-updated.
Last update: 2024-09-29 01:48:11 UTC
README
Tuxedo 是一种通过 Laravel 的 Mail
类发送事务性电子邮件的简单方法,模板已经为您准备好了。
内容
安装
- 运行以下命令
$ composer require tomirons/tuxedo
- 打开您的
config/app.php
并将以下类添加到您的providers
数组中
TomIrons\Tuxedo\TuxedoServiceProvider::class
- (可选) 如果您想编辑模板,运行以下命令以发布它们
php artisan vendor:publish --provider=TomIrons\Tuxedo\TuxedoServiceProvider
类
目前有 3 种不同类型的类可以扩展。 ActionMailable
、AlertMailable
和 InvoiceMailable
,每种都有其特殊属性和方法。
全局方法
这些方法在 所有 类中可用。
greeting($greeting)
- 设置消息的问候语。salutation($salutation)
- 设置消息的结束语。line($line)
- 向消息添加一行文本。
ActionMailable
方法
color($color)
- 设置按钮颜色。可用选项是blue
、green
和red
。action($text, $url)
- 设置按钮文本和 URL。success()
- 将按钮颜色设置为green
。error()
- 将按钮颜色设置为red
。info()
- 将按钮颜色设置为blue
。
示例
<?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use TomIrons\Tuxedo\Mailables\ActionMailable; class ActionMail extends ActionMailable { use Queueable, SerializesModels; /** * Create a new message instance. * * @return void */ public function __construct() { // } /** * Build the message. * * @return $this */ public function build() { return $this->greeting('Hello!') ->line('Some line of text to tell you what exactly is going on.') ->action('Click here to do something fun', url('/')) ->line('Some other information to be displayed after the button.') ->salutation('Regards, Example App'); } }
截图
AlertMailable
方法
info()
- 将警报类型设置为info
。warning()
- 将警报类型设置为warning
。success()
- 将警报类型设置为success
。error()
- 将警报类型设置为error
。type($type)
- 设置警报类型,选项有info
、success
、warning
和error
。message($message)
- 设置在警报中显示的消息。
示例
<?php namespace App\Mail; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use TomIrons\Tuxedo\Mailables\AlertMailable; class AlertMail extends AlertMailable { use Queueable, SerializesModels; /** * Create a new message instance. * * @return void */ public function __construct() { // } /** * Build the message. * * @return $this */ public function build() { return $this->greeting('Hello!') ->info() ->message('Some text goes here to inform the user') ->line('Some line of text to tell you what exactly is going on.') ->salutation('Regards, Example App'); } }
截图
InvoiceMailable
属性
$keys|array
- 设置查找项目名称和价格时要使用的键。
方法
id($id)
- 设置发票 ID。date($date)
- 设置在发票表格顶部显示的日期。due($date)
- 设置发票的到期日。items($items)
- 向发票添加一个项目列表。可接受的变量类型是Collection
和array
。calculate($taxPercent, $shipping)
- 计算税费和最终总金额,必须在添加项目之后调用。
示例
<?php namespace App\Mail; use Carbon\Carbon; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Contracts\Queue\ShouldQueue; use TomIrons\Tuxedo\Mailables\InvoiceMailable; class InvoiceMail extends InvoiceMailable { use Queueable, SerializesModels; /** * Create a new message instance. * * @return void */ public function __construct() { // } /** * Build the message. * * @return $this */ public function build() { return $this->id(123456) ->greeting('Hi John Doe!') ->date(Carbon::now()->format('l, M j Y \a\t g:i a')) ->due(Carbon::now()->addDays(7)->format('l, M j Y \a\t g:i a')) ->action('Click me to pay', url('/')) ->items([ ['product_name' => 'Example Product', 'product_price' => 123.99], ['product_name' => 'Second Product', 'product_price' => 321.99] ]) ->calculate(3, 15) ->salutation('Regards, Example App'); } }
截图
许可证
Tuxedo 是开源软件,许可证为 MIT 许可证