warksit/laravel-mail-chimp-sync

同步 Laravel 模型与 MailChimp 的成员或兴趣

dev-master 2019-01-30 19:19 UTC

This package is auto-updated.

Last update: 2024-08-28 14:22:34 UTC


README

Codeship Status for warksit/laravel-mail-chimp-sync

一个用于同步订阅者和兴趣(使用 eloquent 事件)与 MailChimp(API v3)的 Laravel 5.2+ 包。它唯一的依赖项是 Guzzle 6。

安装

要开始,请要求此包

composer require warksit/laravel-mail-chimp-sync

config/app.php 中添加 ServiceProvider

    'providers' => [
        ...
        Warksit\LaravelMailChimpSync\MailingListServiceProvider::class,
    ],

接下来,运行 vendor:publish 以复制迁移文件。

php artisan vendor:publish --provider="Warksit\LaravelMailChimpSync\MailingListServiceProvider"

运行迁移

php artisan migrate

使用方法

此包有两个主要用途。它同步列表中的订阅者,并同步兴趣组列表的兴趣。它使用 eloquent 事件来检测更改,并使用队列作业来避免 MailChimp 的相对昂贵的调用拖慢程序流程。唯一的例外是删除模型,因为我们需要在记录仍然存在的情况下从 MailChimp 中删除它。

同步订阅者

这允许您将 Eloquent 模型所做的更改与 MailChimp 列表同步。它使用 eloquent 事件。这是通过 Warksit\LaravelMailChimpSync\EloquentTraits\MailChimpSyncMember trait 实现的。这要求模型上有一些方法,这些方法由实现 Warksit\LaravelMailChimpSync\EloquentTraits\CanSyncMailChimpMember 接口强制执行。请参阅文档块以获取更多详细信息。如果您已覆盖 boot() 方法,请确保调用 parent::boot(),如果没有,则无需担心。

    use Warksit\LaravelMailChimpSync\Interfaces\CanSyncMailChimpMember;
    use Warksit\LaravelMailChimpSync\EloquentTraits\MailChimpSyncMember;
    
    class YourModel extends Model implements CanSyncMailChimpMember
    {
        use MailChimpSyncMember
        
        protected static function boot()
        {
            parent::boot();
            ...
        }
    }

同步兴趣

这允许您将 Eloquent 模型所做的更改同步为兴趣组。这是通过 Warksit\LaravelMailChimpSync\EloquentTraits\MailChimpSyncInterest trait 实现的。这要求模型上有一些方法,这些方法由实现 Warksit\LaravelMailChimpSync\EloquentTraits\CanSyncMailChimpInterest 接口强制执行。请参阅文档块以获取更多详细信息。再次,如果您已覆盖 boot() 方法,请确保调用 parent::boot(),如果没有,则无需担心。

    use Warksit\LaravelMailChimpSync\Interfaces\CanSyncMailChimpInterest;
    use Warksit\LaravelMailChimpSync\EloquentTraits\MailChimpSyncInterest;
    
    class YourInterestModel extends Model implements CanSyncMailChimpInterest
    {
        use MailChimpSyncInterest;
        
        protected static function boot()
        {
            parent::boot();
            ...
        }
    }

手动同步

如果您想在其他时间触发模型的同步,只需调用 $memberModel->mailingListSubscribe() 以重新同步成员或 $interestModel->addInterestGroup() 在相关模型上。这对于向成员添加新兴趣特别有用。

贡献

请!这满足了我的需求,但我愿意帮助。如果您发现了一个问题或有一个更好的方法来完成某事,请打开一个问题或拉取请求。有一些测试。为了使集成测试正常工作,请将 .env.example 复制到 .env 并输入您的 MailChimp 凭证。