定制 lacodix/laravel-scoped-mail-config 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

lacodix/laravel-scoped-mail-config

最新稳定版本:v1.2.0

Composer 安装命令:

composer require lacodix/laravel-scoped-mail-config

包简介

A package that enables user or tenant specific mail driver configuration.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package makes it an ease to send mails with dynamic mail configuration. The mail configuration can be provided by any model or class, that implements our HasMailConfig Interface.

With this in mind it is the perfect fit for multi tenancy packages like Laravel-multitenancy by spatie.

It also offers the possibility to keep mail configs in user or team models or even if you just want to be able to offer your admin-user to set a dynamic mail configuration.

Documentation

You can find the entire documentation for this package on our documentation site

Installation

composer require lacodix/laravel-scoped-mail-config

Basic Usage

Just add our interface to your scope model

use Illuminate\Database\Eloquent\Model;
use Lacodix\LaravelScopedMailConfig\Concerns\HasMailConfig;

class Tenant extends Model implements HasMailConfig
{
    public function getMailConfig($name): array {
        return [
            'transport' => 'smtp',
            'host' => 'my.smtp.server',
            'port' => 587,
            'encryption' => null,
            'username' => 'my@email.login',
            'password' => 'mypassword',
            'timeout' => 60,
            'local_domain' => null,
            'from' => [
                'address' => 'my@email.login',
                'name' => 'myname',
            ],
        ];
    }
}

In your AppServiceProvider you now just need to inform the package how it shall resolve the mail configuration. By default the Package resolves the current authenticated user. So if you want to use user specific mail configuration then just skip this step.

use Lacodix\LaravelScopedMailConfig\Facades\ScopedMail;

public function register(): void
{
    ScopedMail::resolveScopeUsing(fn () => Tenant::getCurrentTenant());
}

Then you can send mails with this dynamic configuration just by using our facade like laravel Mail facade:

ScopedMail::to('my@email.de')->send($mailable);

ScopedMail is just extending standard Mail facade, so there are all functionalities, that you already know from laravel Mail

Finally it is also possible to use this facade in tests

ScopedMail::fake();

Testing

composer test

Contributing

Please run the following commands and solve potential problems before committing and think about adding tests for new functionality.

composer rector:test
composer insights
composer csfixer:test
composer phpstan:test

Changelog

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

Credits

License

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

统计信息

  • 总下载量: 779
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-08