Create and Send Digest Emails in Laravel
Published on by Paul Redmond
The Laravel Digest package is a simple way to convert your emails into configurable digests. You can create and send digest emails using various configurable frequency types. For example, using this package, you could send a digest email to the site administrator for every 100 user registrations, a daily digest of all errors logged, or a monthly newsletter for all the posts created.
To use this package, you'll define an observer (i.e., when a new user gets created) that will add a record to the digest:
use Hmones\LaravelDigest\Facades\Digest; public function created(User $user){ $batchId = 'userCreated'; $mailable = UserCreatedMailable::class; $data = ['name' => $user->name]; // Frequency can take values such as: // daily, weekly, monthly, custom, or an // integer threshold (10, 20, 30, etc.) $frequency = 'custom'; Digest::add($batchId, $mailable, $data, $frequency);}
The Laravel Digest package will take care of everything else from this point on, sending emails once the frequency is met.
To get started with this package, check out the source code on GitHub, including installation instructions and usage details.