tomirons/tuxedo

Laravel 5.4 mailables 的简单事务性电子邮件类/模板

v2.0.0 2021-02-26 00:46 UTC

This package is not auto-updated.

Last update: 2024-09-29 01:48:11 UTC


README

Version License Total Downloads Build Status

Tuxedo 是一种通过 Laravel 的 Mail 类发送事务性电子邮件的简单方法,模板已经为您准备好了。

内容

安装

  1. 运行以下命令
$ composer require tomirons/tuxedo
  1. 打开您的 config/app.php 并将以下类添加到您的 providers 数组中
TomIrons\Tuxedo\TuxedoServiceProvider::class
  1. (可选) 如果您想编辑模板,运行以下命令以发布它们
php artisan vendor:publish --provider=TomIrons\Tuxedo\TuxedoServiceProvider

目前有 3 种不同类型的类可以扩展。 ActionMailableAlertMailableInvoiceMailable,每种都有其特殊属性和方法。

全局方法

这些方法在 所有 类中可用。

  • greeting($greeting) - 设置消息的问候语。
  • salutation($salutation) - 设置消息的结束语。
  • line($line) - 向消息添加一行文本。

ActionMailable

方法

  • color($color) - 设置按钮颜色。可用选项是 bluegreenred
  • 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');
    }
}

截图

Action

AlertMailable

方法

  • info() - 将警报类型设置为 info
  • warning() - 将警报类型设置为 warning
  • success() - 将警报类型设置为 success
  • error() - 将警报类型设置为 error
  • type($type) - 设置警报类型,选项有 infosuccesswarningerror
  • 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');
    }
}

截图

Alert

InvoiceMailable

属性

  • $keys|array - 设置查找项目名称和价格时要使用的键。

方法

  • id($id) - 设置发票 ID。
  • date($date) - 设置在发票表格顶部显示的日期。
  • due($date) - 设置发票的到期日。
  • items($items) - 向发票添加一个项目列表。可接受的变量类型是 Collectionarray
  • 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');
    }
}

截图

Invoice

许可证

Tuxedo 是开源软件,许可证为 MIT 许可证