This package automatically subscribes registered users in a Laravel application to a mailchimp list
MIT License
This package automatically subscribes registered users in a Laravel application to a mailchimp list.
To install via composer, run the following command:
composer require dotunj/lara-mailchimp
If you are on Laravel 5.4 or below, register the Dotunj\LaraMailChimp\LaraMailChimpServiceProvider
service provider in the config/app.php
file.
<?php
return [
'providers' => [
/*
* Package Service Providers...
*/
Dotunj\LaraMailChimp\LaraMailChimpServiceProvider::class,
]
]
From Laravel 5.5 and above, the service provider will automatically be registered by Laravel
To publish the config
file, run:
php artisan vendor:publish --provider="Dotunj\LaraMailChimp\LaraMailChimpServiceProvider"
This will publish a lara-mailchimp.php
file to the config directory with the following content:
<?php
return [
'api_key' => env('MAILCHIMP_API_KEY'),
'list_id' => env('MAILCHIMP_LIST_ID'),
];
Next, edit your .env
file with your mailchimp details:
MAILCHIMP_API_KEY=xxxx
MAILCHIMP_LIST_ID=xxxx
To subscribe a user's email on registration to your mailchimp list, import the Dotunj\LaraMailChimp\Events\UserRegistered
event at the top of the User
model. Next, define a $dispatchesEvent
property on the User
model that maps the created
lifecylce hook to the UserRegistered
event.
<?php
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Dotunj\LaraMailChimp\Events\UserRegistered;
class User extends Authenticatable
{
use Notifiable;
protected $dispatchesEvents = [
'created' => UserRegistered::class
];
}
The MIT License (MIT). Please see License File for more information.