lukasss93/laravel-extra-mailable

Laravel Mailables 的额外工具

v1.0 2021-05-25 21:35 UTC

This package is auto-updated.

Last update: 2024-09-17 01:55:29 UTC


README

Laravel Extra Mailable

Version Downloads PHP Laravel License Build Coverage

Laravel Mailables 的额外工具

🚀 安装

您可以使用 composer 安装此包

composer require lukasss93/laravel-extra-mailable

👓 使用方法

  1. 在您的 Mailable 类中添加 ExtraMailable 特性
<?php

namespace App\Mail;

use Illuminate\Mail\Mailable;
use Lukasss93\ExtraMailable\ExtraMailable;

class MyMail extends Mailable
{
    use ExtraMailable;

    protected int $value;

    public function __construct(int $value = 0)
    {
        $this->value = $value;
    }

    public function build() 
    {
        return $this->markdown('emails.myview', ['myvalue' => $this->value]);
    }
}
  1. 如何使用特性
<?php

use App\Mail\MyMail;

// send mail to recipient (string)
MyMail::create()->sendTo('foo@bar.org');

// send mail to recipients (string with semicolon separator)
MyMail::create()->sendTo('foo@bar.org;bar@foo.org');

// send mail to recipients (array)
MyMail::create()->sendTo(['foo@bar.org','bar@foo.org']);

// send mail to recipients (User)
MyMail::create()->sendTo(User::first());

// send mail to recipients (User collection)
MyMail::create()->sendTo(User::all());

// you can pass parameters in the create method
MyMail::create(69)->sendTo('foo@bar.org');

// send mail to recipients when condition is true
MyMail::create()->sendToWhen(true, 'foo@bar.org');

// execute custom code when there is no recipients
MyMail::create()
    ->onEmptyRecipients(fn() => print('No emails sent! No recipient found.'))
    ->sendTo([]);
    
// execute custom code before sending emails
MyMail::create()
    ->onBeforeSendingMails(fn() => print('This message will be printed before sending emails'))
    ->sendTo('foo@bar.org');

// execute custom code after sending emails
MyMail::create()
    ->onAfterSendingMails(fn() => print('This message will be printed after sending emails'))
    ->sendTo('foo@bar.org');

⚗️ 测试

composer test

📃 更新日志

请参阅 CHANGELOG.md 了解最近更改的详细信息。

🏅 致谢

📖 许可证

请参阅 LICENSE.md 文件以获取更多信息。