davidkrenekcz / newsletter
MailChimp newsletter integration
0.5.0
2018-05-30 20:29 UTC
Requires
- php: >=5.6
- composer/installers: ~1.0
- fedeisas/laravel-mail-css-inliner: ~2.2
- idavoll/core-module: >=2.0
- spatie/laravel-newsletter: 3.7.0
- themsaid/laravel-mail-preview: >=1.2.0
Requires (Dev)
- orchestra/testbench: 3.*
- phpunit/phpunit: >=5,7
This package is auto-updated.
Last update: 2024-10-14 04:07:01 UTC
README
Installation
Require to composer
composer require composer require davidkrenekcz/newsletter
Run migrations
php artisan module:migrate Newsletter
Add these providers to config\app.php at the end of array 'providers'
'providers' => [ /* ... current providers ...*/ Modules\Newsletter\Providers\NewsletterInitProvider::class, Fedeisas\LaravelMailCssInliner\LaravelMailCssInlinerServiceProvider::class, Spatie\Newsletter\NewsletterServiceProvider::class, ],
Publish config files, then edit important variables in config/dk-newsletter.php
php artisan vendor:publish --provider="Modules\Newsletter\Providers\NewsletterServiceProvider" php artisan vendor:publish --provider="Spatie\Newsletter\NewsletterServiceProvider"
Frontend usage of form
Include form to your template
@include("newsletter::frontend.form")
You can use variables to define form's classes and texts, see template for more details.
You can include default AJAX form controller to your template
@include("newsletter::frontend.ajax")
or you can write your own.
AJAX form controller automatically sends requests to the server. You can control AJAX behaviour like this:
<script>
window.newsletterAjaxEvents.onInit = function() {
// this function runs right before AJAX request is initialized
// you can show loader here for example
};
window.newsletterAjaxEvents.onDone = function() {
// this function runs right after AJAX request ends
// you can hide loader here for example
};
window.newsletterAjaxEvents.onSuccess = function() {
// this function runs right after AJAX request ends if it was successful
// you can alert user here that his subscription was successful
};
window.newsletterAjaxEvents.onFail = function(errorCode) {
// this function runs right after AJAX request ends if it was unsuccessful
// you can alert user here that his subscription was unsuccessful
// there are a few error codes available:
if (errorCode == "DB_ERROR") {
// error with DB connection
} else if (errorCode == "ALREADY_SUBSCRIBED") {
// user is already subscribed
} else if (errorCode == "INVALID_EMAIL") {
// provided e-mail address is not valid
} else {
// unknown error
}
};
</script>