承接 kirschbaum-development/nova-mail 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kirschbaum-development/nova-mail

Composer 安装命令:

composer require kirschbaum-development/nova-mail

包简介

A Laravel Nova action for sending mail.

关键字:

README 文档

README

banner

Nova Mail

Latest Version on Packagist Total Downloads

This package contains a Nova action that provides a mail sending form for any resource to easily send email. It also includes automated mail sending based on Eloquent Model events/attribute changes.

screenshot of the send mail action modal

screenshot of the send mail action modal with template selected

screenshot of mail template model events

Requirements

This Nova package requires Nova 4.0 or higher. If you are using a Nova version < 4.0, then you'll want to use v1.0.4 (no longer updated).

Using the mail delay feature requires a queue driver other than sync. If you are using the Amazon SQS queue service, the maximum delay time is 15 minutes.

Installation

You can install this package in a Laravel app that uses Nova via composer:

composer require kirschbaum-development/nova-mail

Next, we need to run migrations. Auto-discovery of this package's service provider helps with that!

php artisan migrate

And lastly, any model that you want to send mail needs the Mailable trait added to it. The model should have a compliant email column. You also need to implement the abstract method provided by the Mailable trait, like shown below. You should customize this if your email column name is different:

use KirschbaumDevelopment\NovaMail\Traits\Mailable;

class User extends Model
{
    use Mailable;

    /**
     * Get the name of the email field for the model.
     *
     * @return string
     */
    public function getEmailField(): string
    {
        return 'email';
    }

    // ...
}

If you would like to publish the config for this package, run:

php artisan vendor:publish

And choose the provider for this package: KirschbaumDevelopment\NovaMail\NovaMailServiceProvider

Usage

There is a single action (SendMail) and two resources (NovaMailTemplate and NovaSentMail) that ship with this package. Internally the SendMail action uses a custom Nova field to display the inline mail sending form.

SendMail action

The SendMail action inserts a mail form directly into a Nova action modal. This action allows you to quickly send an email directly to one or more resources.

Simply add the KirschbaumDevelopment\NovaMail\Actions\SendMail action to your Nova resource:

namespace App\Nova;

use KirschbaumDevelopment\NovaMail\Actions\SendMail;

class User extends Resource
{
    // ...

    public function actions(Request $request)
    {
        return [
            // ...

            new SendMail,
        ];
    }
}

Now you can send emails from the action called "Send Mail" on your resource!

You can also delay any outgoing email by setting the delay in minutes property on the template. Like subject and body, you can override the mail delay specified in the template when you send mail.

Trigger Mail on Model Events

A MailTemplate can be configured to respond to Eloquent Model events, or a value change of a specified column. For example, a mail template informing your users of their account status could be sent when the active column on your User model is updated:

screenshot of the account status mail template

You can even have separate Model Events for both "on" an "off"!

screenshot of the account status with value mail template

Mail Template Usage/Caveats

The NovaMailTemplate resource allows you to create re-usable custom templates for sending email. It works by taking your specified template (or over-ridden template content) and building a temporary blade file (the Blade file can be saved permantely via a configuration option). This blade file is then used in the typical Laravel fashion to send the email.

The final content provided when the user clicks the "Send Mail" button is parsed as markdown and makes no assumptions about newlines or any other formatting for that matter. For example, if you were to use the built in mail message component provided by Laravel for markdown emails you could create a template like the following:

@component('mail::message')
Hello {{ $name }},

Visit this link when you have a moment:

[https://github.com/kirschbaum-development/nova-mail](https://github.com/kirschbaum-development/nova-mail)

Let me know if you have any questions.

@include('path.to.footer')
@endcomponent

screenshot of the create mail template

Sent Mail Usage

The NovaSentMail resource can be added as a relationship field to any Resource that has the Mailable trait defined on it's corresponding model. This gives you direct access to the history of emails sent from that Resource:

namespace App\Nova;

use Laravel\Nova\Fields\HasMany;
use KirschbaumDevelopment\NovaMail\Nova\NovaSentMail;

class User extends Resource
{
    // ...

    public function fields(Request $request)
    {
        return [
            // ...

            HasMany::make('Sent Mail', 'mails', NovaSentMail::class),

            // ...
        ];
    }
}

screenshot of the sent mail index

Resource Customization

In case you need to customize the Nova Resources that you're using in your application, for instance, to add filters, cards or add fields. You can change the default set of classes. First, you'll need to override the array of Resources found in the config file (If you haven't published a config file yet please see the Installation section):

    /*
    |--------------------------------------------------------------------------
    | Default Resources
    |--------------------------------------------------------------------------
    |
    | This determines which Nova Resources you're using
    | You can change it as you wish
    |
    */
    'default_resources' => [
        'nova_mail_event' => App\Nova\YourNovaMailEventResource::class,
        'nova_mail_template' => App\Nova\YourNovaMailTemplateResource::class,
        'nova_sent_mail' => App\Nova\YourNovaSentMailResource::class,
    ],

After that you can extends the default Resource Class and add your custom code like this:

use KirschbaumDevelopment\NovaMail\Nova\NovaSentMail;

class YourNovaSentMailResource extends NovaSentMail
{
    public function cards(Request $request)
    {
        return [
            // Your custom code...
        ];
    }
}

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email adam@kirschbaumdevelopment.com or nathan@kirschbaumdevelopment.com instead of using the issue tracker.

Credits

Sponsorship

Development of this package is sponsored by Kirschbaum Development Group, a developer driven company focused on problem solving, team building, and community. Learn more about us or join us!

License

The MIT License (MIT). Please see License File for more information.

kirschbaum-development/nova-mail 适用场景与选型建议

kirschbaum-development/nova-mail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 88.12k 次下载、GitHub Stars 达 74, 最近一次更新时间为 2019 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nova」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kirschbaum-development/nova-mail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kirschbaum-development/nova-mail 我们能提供哪些服务?
定制开发 / 二次开发

基于 kirschbaum-development/nova-mail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 88.12k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 74
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 74
  • Watchers: 14
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-07